diff --git a/Phaser/cameras/Camera.ts b/Phaser/cameras/Camera.ts index 40de72f8..6d997fef 100644 --- a/Phaser/cameras/Camera.ts +++ b/Phaser/cameras/Camera.ts @@ -35,7 +35,7 @@ module Phaser { this._stageX = x; this._stageY = y; this.scaledX = x; - this.scaledY = x; + this.scaledY = y; this.fx = new CameraFX(this._game, this); // The view into the world canvas we wish to render @@ -194,12 +194,7 @@ module Phaser { */ public isHidden(object): bool { - if (object['cameraBlacklist'] && object['cameraBlacklist'].length > 0 && object['cameraBlacklist'].indexOf(this.ID) == -1) - { - return true; - } - - return false; + return (object['cameraBlacklist'] && object['cameraBlacklist'].length > 0 && object['cameraBlacklist'].indexOf(this.ID) == -1); } diff --git a/Phaser/components/sprite/Events.ts b/Phaser/components/sprite/Events.ts index 6e2b1ef9..64150922 100644 --- a/Phaser/components/sprite/Events.ts +++ b/Phaser/components/sprite/Events.ts @@ -10,6 +10,10 @@ module Phaser.Components { export class Events { + /** + * The Events component is a collection of events fired by the parent Sprite and its other components. + * @param parent The Sprite using this Input component + */ constructor(parent: Sprite) { this.game = parent.game; @@ -22,7 +26,14 @@ module Phaser.Components { } + /** + * Reference to Phaser.Game + */ public game: Game; + + /** + * Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite. + */ private _sprite: Sprite; // Creation and destruction @@ -33,9 +44,25 @@ module Phaser.Components { public onOutOfBounds: Phaser.Signal; // Input related events + + /** + * Dispatched by the Input component when a pointer moves over an Input enabled sprite. + */ public onInputOver: Phaser.Signal; + + /** + * Dispatched by the Input component when a pointer moves out of an Input enabled sprite. + */ public onInputOut: Phaser.Signal; + + /** + * Dispatched by the Input component when a pointer is pressed down on an Input enabled sprite. + */ public onInputDown: Phaser.Signal; + + /** + * Dispatched by the Input component when a pointer is released over an Input enabled sprite + */ public onInputUp: Phaser.Signal; } diff --git a/Phaser/components/sprite/Input.ts b/Phaser/components/sprite/Input.ts index d059e4dd..6b64f606 100644 --- a/Phaser/components/sprite/Input.ts +++ b/Phaser/components/sprite/Input.ts @@ -13,6 +13,10 @@ module Phaser.Components { export class Input { + /** + * Sprite Input component constructor + * @param parent The Sprite using this Input component + */ constructor(parent: Sprite) { this.game = parent.game; @@ -26,7 +30,7 @@ module Phaser.Components { } /** - * + * Reference to Phaser.Game */ public game: Game; @@ -35,14 +39,38 @@ module Phaser.Components { */ private _sprite: Sprite; + /** + * If enabled the Input component will be updated by the parent Sprite + * @type {Boolean} + */ public enabled: bool; + + /** + * The Input component can monitor either the physics body of the Sprite or the frameBounds + * If checkBody is set to true it will monitor the bounds of the physics body. + * @type {Boolean} + */ public checkBody: bool; + + /** + * Turn the mouse pointer into a hand image by temporarily setting the CSS style of the Game canvas + * on Input over. Only works on desktop browsers or browsers with a visible input pointer. + * @type {Boolean} + */ public useHandCursor: bool; - public oldX: number; - public oldY: number; - + /** + * The x coordinate of the Input pointer, relative to the top-left of the parent Sprite. + * This value is only set with the pointer is over this Sprite. + * @type {number} + */ public x: number = 0; + + /** + * The y coordinate of the Input pointer, relative to the top-left of the parent Sprite + * This value is only set with the pointer is over this Sprite. + * @type {number} + */ public y: number = 0; /** @@ -87,6 +115,10 @@ module Phaser.Components { **/ public isOut: bool = true; + public oldX: number; + public oldY: number; + + /** * Update */ @@ -142,14 +174,28 @@ module Phaser.Components { } + /** + * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second) + * @param delay The time below which the pointer is considered as just over. + * @returns {boolean} + */ public justOver(delay?:number = 500): bool { return (this.isOver && this.duration < delay); } + /** + * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second) + * @param delay The time below which the pointer is considered as just out. + * @returns {boolean} + */ public justOut(delay?:number = 500): bool { return (this.isOut && (this.game.time.now - this.timeOut < delay)); } + /** + * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds. + * @returns {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over. + */ public get duration(): number { if (this.isOver) diff --git a/Phaser/components/sprite/Texture.ts b/Phaser/components/sprite/Texture.ts index a9c9da21..dcead1b3 100644 --- a/Phaser/components/sprite/Texture.ts +++ b/Phaser/components/sprite/Texture.ts @@ -12,9 +12,14 @@ module Phaser.Components { export class Texture { + /** + * Creates a new Sprite Texture component + * @param parent The Sprite using this Texture to render + * @param key An optional Game.Cache key to load an image from + */ constructor(parent: Sprite, key?: string = '') { - this._game = parent.game; + this.game = parent.game; this._sprite = parent; this.canvas = parent.game.stage.canvas; @@ -31,13 +36,14 @@ module Phaser.Components { } - /** - * - */ - private _game: Game; /** - * Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite. + * Reference to Phaser.Game + */ + public game: Game; + + /** + * Reference to the parent Sprite */ private _sprite: Sprite; @@ -53,7 +59,7 @@ module Phaser.Components { public dynamicTexture: DynamicTexture = null; /** - * The status of the texture image. + * The load status of the texture image. * @type {boolean} */ public loaded: bool = false; @@ -141,7 +147,6 @@ module Phaser.Components { * The graphic can be SpriteSheet or Texture Atlas. If you need to use a DynamicTexture see loadDynamicTexture. * @param key {string} Key of the graphic you want to load for this sprite. * @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean - * @return {Sprite} Sprite instance itself. */ public loadImage(key: string, clearAnimations?: bool = true, updateBody?: bool = true) { @@ -150,11 +155,11 @@ module Phaser.Components { this._sprite.animations.destroy(); } - if (this._game.cache.getImage(key) !== null) + if (this.game.cache.getImage(key) !== null) { - this.setTo(this._game.cache.getImage(key), null); + this.setTo(this.game.cache.getImage(key), null); - if (this._game.cache.isSpriteSheet(key)) + if (this.game.cache.isSpriteSheet(key)) { this._sprite.animations.loadFrameData(this._sprite.game.cache.getFrameData(key)); } @@ -176,7 +181,6 @@ module Phaser.Components { /** * Load a DynamicTexture as its texture. * @param texture {DynamicTexture} The texture object to be used by this sprite. - * @return {Sprite} Sprite instance itself. */ public loadDynamicTexture(texture: DynamicTexture) { diff --git a/Phaser/gameobjects/ScrollZone.ts b/Phaser/gameobjects/ScrollZone.ts index 6b1c1e07..2044a00d 100644 --- a/Phaser/gameobjects/ScrollZone.ts +++ b/Phaser/gameobjects/ScrollZone.ts @@ -85,7 +85,7 @@ module Phaser { if (x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) { throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone'); - return; + return null; } this.currentRegion = new ScrollRegion(x, y, width, height, speedX, speedY); diff --git a/Phaser/gameobjects/Tilemap.ts b/Phaser/gameobjects/Tilemap.ts index 4c2a186f..f7d2bc4c 100644 --- a/Phaser/gameobjects/Tilemap.ts +++ b/Phaser/gameobjects/Tilemap.ts @@ -214,7 +214,7 @@ module Phaser { } /** - * Parset JSON map data and generate tiles. + * Parse JSON map data and generate tiles. * @param data {string} JSON map data. * @param key {string} Asset key for tileset image. */ @@ -384,6 +384,11 @@ module Phaser { } + /** + * Gets the tile underneath the Input.x/y position + * @param layer The layer to check, defaults to 0 + * @returns {Tile} + */ public getTileFromInputXY(layer?: number = 0):Tile { return this.tiles[this.layers[layer].getTileFromWorldXY(this.game.input.getWorldX(), this.game.input.getWorldY())]; @@ -393,7 +398,7 @@ module Phaser { /** * Get tiles overlaps the given object. * @param object {GameObject} Tiles you want to get that overlaps this. - * @return {array} Array with tiles informations. (Each contains x, y and the tile.) + * @return {array} Array with tiles information. (Each contains x, y and the tile.) */ public getTileOverlaps(object: Sprite) { diff --git a/Phaser/phaser.js b/Phaser/phaser.js index 7b20a194..4d4cebd0 100644 --- a/Phaser/phaser.js +++ b/Phaser/phaser.js @@ -1,20 +1,5 @@ -/** -* Phaser -* -* v1.0.0 - June XX 2013 -* -* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi. -* -* Richard Davey (@photonstorm) -* -* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser -* and my love of game development took a lot of inspiration. -* -* "If you want your children to be intelligent, read them fairy tales." -* "If you want them to be more intelligent, read them more fairy tales." -* -- Albert Einstein -*/ var Phaser; (function (Phaser) { Phaser.VERSION = 'Phaser version 1.0.0'; })(Phaser || (Phaser = {})); +//@ sourceMappingURL=Phaser.js.map