From 51049128f5fc8695aa6878d55efe22b2a8e1f56f Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 23 Sep 2013 22:23:17 +0100 Subject: [PATCH] Collision fixes for testing --- Docs/jsdoc_work.txt | 74 ++++++++++++++++++++++++++++++++++++++ README.md | 3 +- src/Phaser.js | 8 ++++- src/core/StateManager.js | 6 +++- src/gameobjects/Sprite.js | 22 ++++++++++++ src/physics/arcade/Body.js | 29 +++++++++++++++ 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 Docs/jsdoc_work.txt diff --git a/Docs/jsdoc_work.txt b/Docs/jsdoc_work.txt new file mode 100644 index 00000000..03fb7337 --- /dev/null +++ b/Docs/jsdoc_work.txt @@ -0,0 +1,74 @@ +JSDOC3 Work: + +1) This should go at the top of every file (with the module name corrected) + +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.Animation +*/ + +2) This is the format a constructor should be: + +/** +* The constructor description goes here. If there isn't one for you to paste in, just put TODO. +* +* @class Phaser.Animation +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +* @param {Phaser.Sprite} parent - A reference to the owner of this Animation. +* @param {string} name - The unique name for this animation, used in playback commands. +* @param {Phaser.Animation.FrameData} frameData - The FrameData object that contains all frames used by this Animation. +* @param {(Array.|Array.)} frames - An array of numbers or strings indicating which frames to play in which order. +* @param {number} delay - The time between each frame of the animation, given in ms. +* @param {boolean} looped - Should this animation loop or play through once. +*/ + +You must ensure the class is correct and it has the @constructor tag. +It is important you include the data-type. I don't expect you to know what the data type is, so just include: {todo} +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. +You often won't know what the parameter description is, so just put "todo", like this: + +* @param {todo} name - todo. + +3) Functions are nearly exactly the same as the constructor: + +/** +* The function description goes here. If there isn't one for you to paste in, just put TODO. +* +* @method play +* @param {Number} [frameRate=null] The framerate to play the animation at. +* @return {Phaser.Animation} A reference to this Animation instance. +*/ + +You must ensure the @method tag is correct and present. +It is important you include the data-type. I don't expect you to know what the data type is, so just include: {todo} +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. +You often won't know what the parameter description is, so just put "todo", like this: + +* @param {todo} name - todo. + +4) All properties must be marked-up: + +/** +* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback. +* @default +*/ +this.isFinished = false; + +It is important you include the data-type. I don't expect you to know what the data type is, so just include: {todo} +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. +You often won't know what the parameter description is, so just put "todo", like this: + +* @property {todo} isFinished - todo. + +If the property has a base value assigned to it (i.e. a number or a string) then put @default. +If the property starts with an underscore it must include @private. Here is an example combining the two: + +/** +* @property {number} _frameIndex - The index of the current frame. +* @private +* @default +*/ +this._frameIndex = 0; diff --git a/README.md b/README.md index 82e5eea7..97b47c66 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,8 @@ Version 1.0.6 (in progress) * Updated ArcadePhysics.separateX/Y to use new body system - much better results now. * QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values. * Several new examples added (cameras, tweens, etc) - +* TODO: addMarker hh:mm:ss:ms +* TODO: Direction constants Version 1.0.5 (September 20th 2013) diff --git a/src/Phaser.js b/src/Phaser.js index fce79be0..a3265766 100644 --- a/src/Phaser.js +++ b/src/Phaser.js @@ -20,7 +20,13 @@ var Phaser = Phaser || { RENDERTEXTURE: 8, TILEMAP: 9, TILEMAPLAYER: 10, - EMITTER: 11 + EMITTER: 11, + + NONE: 0, + LEFT: 1, + RIGHT: 2, + UP: 3, + DOWN: 4 }; diff --git a/src/core/StateManager.js b/src/core/StateManager.js index 04406442..86a2b8c6 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -368,9 +368,13 @@ Phaser.StateManager.prototype = { if (this._created == false && this.onCreateCallback) { // console.log('Create callback found'); + this._created = true; this.onCreateCallback.call(this.callbackContext); } - this._created = true; + else + { + this._created = true; + } }, diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index be395d24..39b499fb 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -99,6 +99,9 @@ Phaser.Sprite = function (game, x, y, key, frame) { this.x = x; this.y = y; + this.prevX = x; + this.prevY = y; + this.position.x = x; this.position.y = y; @@ -215,6 +218,9 @@ Phaser.Sprite.prototype.preUpdate = function() { this.renderOrderID = this.game.world.currentRenderOrderID++; } + this.prevX = this.x; + this.prevY = this.y; + // |a c tx| // |b d ty| // |0 0 1| @@ -308,6 +314,22 @@ Phaser.Sprite.prototype.postUpdate = function() { } +Phaser.Sprite.prototype.deltaAbsX = function () { + return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX()); +} + +Phaser.Sprite.prototype.deltaAbsY = function () { + return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY()); +} + +Phaser.Sprite.prototype.deltaX = function () { + return this.x - this.prevX; +} + +Phaser.Sprite.prototype.deltaY = function () { + return this.y - this.prevY; +} + /** * Moves the sprite so its center is located on the given x and y coordinates. * Doesn't change the origin of the sprite. diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index 7f64ad5b..4e061e51 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -44,6 +44,7 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true }; this.touching = { none: true, up: false, down: false, left: false, right: false }; this.wasTouching = { none: true, up: false, down: false, left: false, right: false }; + this.facing = Phaser.NONE; this.immovable = false; this.moves = true; @@ -130,6 +131,34 @@ Phaser.Physics.Arcade.Body.prototype = { postUpdate: function () { + // Calculate forward-facing edge + if (this.deltaX() == 0 && this.deltaY() == 0) + { + // Can't work it out from the Body, how about from x position? + if (this.sprite.deltaX() == 0 && this.sprite.deltaY() == 0) + { + // still as a statue + } + } + + if (this.deltaX() < 0) + { + this.facing = Phaser.LEFT; + } + else if (this.deltaX() > 0) + { + this.facing = Phaser.RIGHT; + } + + if (this.deltaY() < 0) + { + this.facing = Phaser.UP; + } + else if (this.deltaY() > 0) + { + this.facing = Phaser.DOWN; + } + if (this.deltaX() != 0) { this.sprite.x += this.deltaX();