From 1b6fbc1324baae0b972e238ff106834b40b38012 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 24 Apr 2013 00:47:11 +0100 Subject: [PATCH] Fixed Game.boot issue and Animation issue reported in github. --- Phaser/AnimationManager.ts | 1 + Phaser/Game.ts | 12 +++++++++--- Phaser/system/animation/Animation.ts | 3 +++ Phaser/system/input/Keyboard.ts | 18 ++++++++++++++++-- README.md | 7 +++++-- Tests/phaser.js | 25 +++++++++++++++++++++---- build/phaser.js | 25 +++++++++++++++++++++---- 7 files changed, 76 insertions(+), 15 deletions(-) diff --git a/Phaser/AnimationManager.ts b/Phaser/AnimationManager.ts index c638e152..c8f1473d 100644 --- a/Phaser/AnimationManager.ts +++ b/Phaser/AnimationManager.ts @@ -70,6 +70,7 @@ module Phaser { this._anims[name] = new Animation(this._game, this._parent, this._frameData, name, frames, frameRate, loop); this.currentAnim = this._anims[name]; + this.currentFrame = this.currentAnim.currentFrame; } diff --git a/Phaser/Game.ts b/Phaser/Game.ts index 5c4f79a4..23d6c44a 100644 --- a/Phaser/Game.ts +++ b/Phaser/Game.ts @@ -33,8 +33,8 @@ /** * Phaser - Game * -* This is where the magic happens. The Game object is the heart of your game, providing quick access to common -* functions and handling the boot process. +* This is where the magic happens. The Game object is the heart of your game, +* providing quick access to common functions and handling the boot process. */ module Phaser { @@ -51,11 +51,12 @@ module Phaser { if (document.readyState === 'complete' || document.readyState === 'interactive') { - this.boot(parent, width, height); + setTimeout((parent, width, height) => this.boot(parent, width, height)); } else { document.addEventListener('DOMContentLoaded', () => this.boot(parent, width, height), false); + window.addEventListener('load', () => this.boot(parent, width, height), false); } } @@ -95,6 +96,11 @@ module Phaser { private boot(parent: string, width: number, height: number) { + if (this.isBooted == true) + { + return; + } + if (!document.body) { window.setTimeout(() => this.boot(parent, width, height), 13); diff --git a/Phaser/system/animation/Animation.ts b/Phaser/system/animation/Animation.ts index 5a4a67a7..bcc7161a 100644 --- a/Phaser/system/animation/Animation.ts +++ b/Phaser/system/animation/Animation.ts @@ -24,6 +24,9 @@ module Phaser { this.isFinished = false; this.isPlaying = false; + this._frameIndex = 0; + this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); + } private _game: Game; diff --git a/Phaser/system/input/Keyboard.ts b/Phaser/system/input/Keyboard.ts index c8e25a18..332806f4 100644 --- a/Phaser/system/input/Keyboard.ts +++ b/Phaser/system/input/Keyboard.ts @@ -30,12 +30,26 @@ module Phaser { } - public addKeyCapture(keycode: number) { - this._capture[keycode] = true; + public addKeyCapture(keycode) { + + if (typeof keycode == 'array') + { + for (var code in keycode) + { + this._capture[code] = true; + } + } + else + { + this._capture[keycode] = true; + } + } public removeKeyCapture(keycode: number) { + delete this._capture[keycode]; + } public clearCaptures() { diff --git a/README.md b/README.md index ef934c0b..209992da 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Phaser Version 0.9.3 -23rd April 2013 +24th April 2013 By Richard Davey, [Photon Storm](http://www.photonstorm.com) @@ -27,7 +27,10 @@ V0.9.3 * Added shiftSinTable and shiftCosTable to the GameMath class to allow for quick iteration through the data tables. * Added the new ScrollZone game object. Endlessly useful but especially for scrolling backdrops. Created 6 example tests. * Removed the need for DynamicTextures to require a key property and updated test cases. -* Add the rotationOffset value to GameObject (and thus Sprite). Useful if your graphics need to rotate but don't weren't drawn facing zero degrees (to the right). +* Add the rotationOffset value to GameObject (and thus Sprite). Useful if your graphics need to rotate but weren't drawn facing zero degrees (to the right). +* You can now pass an array or a single value to Input.Keyboard.addKeyCapture() +* Fixed a potential race condition issue in Game.boot (thanks Hackmaniac) +* Fixed issue with showing frame zero of a texture atlas before the animation started playing (thanks JesseFreeman) V0.9.2 diff --git a/Tests/phaser.js b/Tests/phaser.js index a02d494a..4ee8b39a 100644 --- a/Tests/phaser.js +++ b/Tests/phaser.js @@ -1666,6 +1666,8 @@ var Phaser; this.looped = looped; this.isFinished = false; this.isPlaying = false; + this._frameIndex = 0; + this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); } Object.defineProperty(Animation.prototype, "frameTotal", { get: function () { @@ -1982,6 +1984,7 @@ var Phaser; } this._anims[name] = new Phaser.Animation(this._game, this._parent, this._frameData, name, frames, frameRate, loop); this.currentAnim = this._anims[name]; + this.currentFrame = this.currentAnim.currentFrame; }; AnimationManager.prototype.validateFrames = function (frames, useNumericIndex) { for(var i = 0; i < frames.length; i++) { @@ -9477,7 +9480,13 @@ var Phaser; }, false); }; Keyboard.prototype.addKeyCapture = function (keycode) { - this._capture[keycode] = true; + if(typeof keycode == 'array') { + for(var code in keycode) { + this._capture[code] = true; + } + } else { + this._capture[keycode] = true; + } }; Keyboard.prototype.removeKeyCapture = function (keycode) { delete this._capture[keycode]; @@ -11217,8 +11226,8 @@ var Phaser; /** * Phaser - Game * -* This is where the magic happens. The Game object is the heart of your game, providing quick access to common -* functions and handling the boot process. +* This is where the magic happens. The Game object is the heart of your game, +* providing quick access to common functions and handling the boot process. */ var Phaser; (function (Phaser) { @@ -11250,15 +11259,23 @@ var Phaser; this.onUpdateCallback = updateCallback; this.onRenderCallback = renderCallback; if(document.readyState === 'complete' || document.readyState === 'interactive') { - this.boot(parent, width, height); + setTimeout(function (parent, width, height) { + return _this.boot(parent, width, height); + }); } else { document.addEventListener('DOMContentLoaded', function () { return _this.boot(parent, width, height); }, false); + window.addEventListener('load', function () { + return _this.boot(parent, width, height); + }, false); } } Game.prototype.boot = function (parent, width, height) { var _this = this; + if(this.isBooted == true) { + return; + } if(!document.body) { window.setTimeout(function () { return _this.boot(parent, width, height); diff --git a/build/phaser.js b/build/phaser.js index a02d494a..4ee8b39a 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -1666,6 +1666,8 @@ var Phaser; this.looped = looped; this.isFinished = false; this.isPlaying = false; + this._frameIndex = 0; + this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); } Object.defineProperty(Animation.prototype, "frameTotal", { get: function () { @@ -1982,6 +1984,7 @@ var Phaser; } this._anims[name] = new Phaser.Animation(this._game, this._parent, this._frameData, name, frames, frameRate, loop); this.currentAnim = this._anims[name]; + this.currentFrame = this.currentAnim.currentFrame; }; AnimationManager.prototype.validateFrames = function (frames, useNumericIndex) { for(var i = 0; i < frames.length; i++) { @@ -9477,7 +9480,13 @@ var Phaser; }, false); }; Keyboard.prototype.addKeyCapture = function (keycode) { - this._capture[keycode] = true; + if(typeof keycode == 'array') { + for(var code in keycode) { + this._capture[code] = true; + } + } else { + this._capture[keycode] = true; + } }; Keyboard.prototype.removeKeyCapture = function (keycode) { delete this._capture[keycode]; @@ -11217,8 +11226,8 @@ var Phaser; /** * Phaser - Game * -* This is where the magic happens. The Game object is the heart of your game, providing quick access to common -* functions and handling the boot process. +* This is where the magic happens. The Game object is the heart of your game, +* providing quick access to common functions and handling the boot process. */ var Phaser; (function (Phaser) { @@ -11250,15 +11259,23 @@ var Phaser; this.onUpdateCallback = updateCallback; this.onRenderCallback = renderCallback; if(document.readyState === 'complete' || document.readyState === 'interactive') { - this.boot(parent, width, height); + setTimeout(function (parent, width, height) { + return _this.boot(parent, width, height); + }); } else { document.addEventListener('DOMContentLoaded', function () { return _this.boot(parent, width, height); }, false); + window.addEventListener('load', function () { + return _this.boot(parent, width, height); + }, false); } } Game.prototype.boot = function (parent, width, height) { var _this = this; + if(this.isBooted == true) { + return; + } if(!document.body) { window.setTimeout(function () { return _this.boot(parent, width, height);