Skip to content

Commit 5104912

Browse files
committed
Collision fixes for testing
1 parent 257cbe3 commit 5104912

6 files changed

Lines changed: 139 additions & 3 deletions

File tree

Docs/jsdoc_work.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
JSDOC3 Work:
2+
3+
1) This should go at the top of every file (with the module name corrected)
4+
5+
/**
6+
* @author Richard Davey <rich@photonstorm.com>
7+
* @copyright 2013 Photon Storm Ltd.
8+
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
9+
* @module Phaser.Animation
10+
*/
11+
12+
2) This is the format a constructor should be:
13+
14+
/**
15+
* The constructor description goes here. If there isn't one for you to paste in, just put TODO.
16+
*
17+
* @class Phaser.Animation
18+
* @constructor
19+
* @param {Phaser.Game} game - A reference to the currently running game.
20+
* @param {Phaser.Sprite} parent - A reference to the owner of this Animation.
21+
* @param {string} name - The unique name for this animation, used in playback commands.
22+
* @param {Phaser.Animation.FrameData} frameData - The FrameData object that contains all frames used by this Animation.
23+
* @param {(Array.<number>|Array.<string>)} frames - An array of numbers or strings indicating which frames to play in which order.
24+
* @param {number} delay - The time between each frame of the animation, given in ms.
25+
* @param {boolean} looped - Should this animation loop or play through once.
26+
*/
27+
28+
You must ensure the class is correct and it has the @constructor tag.
29+
It is important you include the data-type. I don't expect you to know what the data type is, so just include: {todo}
30+
It is important you include the hypen after the parameter name. You will always know what the parameter name is, so it should always be included.
31+
You often won't know what the parameter description is, so just put "todo", like this:
32+
33+
* @param {todo} name - todo.
34+
35+
3) Functions are nearly exactly the same as the constructor:
36+
37+
/**
38+
* The function description goes here. If there isn't one for you to paste in, just put TODO.
39+
*
40+
* @method play
41+
* @param {Number} [frameRate=null] The framerate to play the animation at.
42+
* @return {Phaser.Animation} A reference to this Animation instance.
43+
*/
44+
45+
You must ensure the @method tag is correct and present.
46+
It is important you include the data-type. I don't expect you to know what the data type is, so just include: {todo}
47+
It is important you include the hypen after the parameter name. You will always know what the parameter name is, so it should always be included.
48+
You often won't know what the parameter description is, so just put "todo", like this:
49+
50+
* @param {todo} name - todo.
51+
52+
4) All properties must be marked-up:
53+
54+
/**
55+
* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
56+
* @default
57+
*/
58+
this.isFinished = false;
59+
60+
It is important you include the data-type. I don't expect you to know what the data type is, so just include: {todo}
61+
It is important you include the hypen after the parameter name. You will always know what the parameter name is, so it should always be included.
62+
You often won't know what the parameter description is, so just put "todo", like this:
63+
64+
* @property {todo} isFinished - todo.
65+
66+
If the property has a base value assigned to it (i.e. a number or a string) then put @default.
67+
If the property starts with an underscore it must include @private. Here is an example combining the two:
68+
69+
/**
70+
* @property {number} _frameIndex - The index of the current frame.
71+
* @private
72+
* @default
73+
*/
74+
this._frameIndex = 0;

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Version 1.0.6 (in progress)
5151
* Updated ArcadePhysics.separateX/Y to use new body system - much better results now.
5252
* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values.
5353
* Several new examples added (cameras, tweens, etc)
54-
54+
* TODO: addMarker hh:mm:ss:ms
55+
* TODO: Direction constants
5556

5657

5758
Version 1.0.5 (September 20th 2013)

src/Phaser.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ var Phaser = Phaser || {
2020
RENDERTEXTURE: 8,
2121
TILEMAP: 9,
2222
TILEMAPLAYER: 10,
23-
EMITTER: 11
23+
EMITTER: 11,
24+
25+
NONE: 0,
26+
LEFT: 1,
27+
RIGHT: 2,
28+
UP: 3,
29+
DOWN: 4
2430

2531
};
2632

src/core/StateManager.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,13 @@ Phaser.StateManager.prototype = {
368368
if (this._created == false && this.onCreateCallback)
369369
{
370370
// console.log('Create callback found');
371+
this._created = true;
371372
this.onCreateCallback.call(this.callbackContext);
372373
}
373-
this._created = true;
374+
else
375+
{
376+
this._created = true;
377+
}
374378

375379
},
376380

src/gameobjects/Sprite.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Phaser.Sprite = function (game, x, y, key, frame) {
9999
this.x = x;
100100
this.y = y;
101101

102+
this.prevX = x;
103+
this.prevY = y;
104+
102105
this.position.x = x;
103106
this.position.y = y;
104107

@@ -215,6 +218,9 @@ Phaser.Sprite.prototype.preUpdate = function() {
215218
this.renderOrderID = this.game.world.currentRenderOrderID++;
216219
}
217220

221+
this.prevX = this.x;
222+
this.prevY = this.y;
223+
218224
// |a c tx|
219225
// |b d ty|
220226
// |0 0 1|
@@ -308,6 +314,22 @@ Phaser.Sprite.prototype.postUpdate = function() {
308314

309315
}
310316

317+
Phaser.Sprite.prototype.deltaAbsX = function () {
318+
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
319+
}
320+
321+
Phaser.Sprite.prototype.deltaAbsY = function () {
322+
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
323+
}
324+
325+
Phaser.Sprite.prototype.deltaX = function () {
326+
return this.x - this.prevX;
327+
}
328+
329+
Phaser.Sprite.prototype.deltaY = function () {
330+
return this.y - this.prevY;
331+
}
332+
311333
/**
312334
* Moves the sprite so its center is located on the given x and y coordinates.
313335
* Doesn't change the origin of the sprite.

src/physics/arcade/Body.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
4444
this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
4545
this.touching = { none: true, up: false, down: false, left: false, right: false };
4646
this.wasTouching = { none: true, up: false, down: false, left: false, right: false };
47+
this.facing = Phaser.NONE;
4748

4849
this.immovable = false;
4950
this.moves = true;
@@ -130,6 +131,34 @@ Phaser.Physics.Arcade.Body.prototype = {
130131

131132
postUpdate: function () {
132133

134+
// Calculate forward-facing edge
135+
if (this.deltaX() == 0 && this.deltaY() == 0)
136+
{
137+
// Can't work it out from the Body, how about from x position?
138+
if (this.sprite.deltaX() == 0 && this.sprite.deltaY() == 0)
139+
{
140+
// still as a statue
141+
}
142+
}
143+
144+
if (this.deltaX() < 0)
145+
{
146+
this.facing = Phaser.LEFT;
147+
}
148+
else if (this.deltaX() > 0)
149+
{
150+
this.facing = Phaser.RIGHT;
151+
}
152+
153+
if (this.deltaY() < 0)
154+
{
155+
this.facing = Phaser.UP;
156+
}
157+
else if (this.deltaY() > 0)
158+
{
159+
this.facing = Phaser.DOWN;
160+
}
161+
133162
if (this.deltaX() != 0)
134163
{
135164
this.sprite.x += this.deltaX();

0 commit comments

Comments
 (0)