From c1d60d7e19b29c54c3c0a5fd2d33681bd47f49c2 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 4 Nov 2013 00:04:19 +0000 Subject: [PATCH] getAnimation and RAF callback ID checks added --- README.md | 4 +++- src/animation/AnimationManager.js | 21 +++++++++++++++++++++ src/system/RequestAnimationFrame.js | 13 ++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d400587f..3db34021 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,9 @@ Change Log Version 1.1.3 - in build -* +* New: Sprite.animations.getAnimation will return an animation instance which was added by name. +* Updated: RequestAnimationFrame now retains the callbackID which is passed to cancelRequestAnimationFrame. + Version 1.1.2 - November 1st 2013 diff --git a/src/animation/AnimationManager.js b/src/animation/AnimationManager.js index 68f6d445..0de12ac3 100644 --- a/src/animation/AnimationManager.js +++ b/src/animation/AnimationManager.js @@ -261,6 +261,27 @@ Phaser.AnimationManager.prototype = { }, + /** + * Returns an animation that was previously added by name. + * + * @method Phaser.AnimationManager#getAnimation + * @param {string} name - The name of the animation to be returned, e.g. "fire". + * @return {Phaser.Animation|boolean} The Animation instance, if found, otherwise false. + */ + getAnimation: function (name) { + + if (typeof name == 'string') + { + if (this._anims[name]) + { + return this._anims[name]; + } + } + + return false; + + }, + /** * Refreshes the current frame data back to the parent Sprite and also resets the texture data. * diff --git a/src/system/RequestAnimationFrame.js b/src/system/RequestAnimationFrame.js index 6fe2ae74..8d3ca09f 100644 --- a/src/system/RequestAnimationFrame.js +++ b/src/system/RequestAnimationFrame.js @@ -50,6 +50,13 @@ Phaser.RequestAnimationFrame = function(game) { */ this._onLoop = null; + /** + * The callback ID used when calling cancel + * @property _timeOutID + * @private + */ + this._timeOutID = null; + }; Phaser.RequestAnimationFrame.prototype = { @@ -83,7 +90,7 @@ Phaser.RequestAnimationFrame.prototype = { return _this.updateRAF(time); }; - window.requestAnimationFrame(this._onLoop); + this._timeOutID = window.requestAnimationFrame(this._onLoop); } }, @@ -97,7 +104,7 @@ Phaser.RequestAnimationFrame.prototype = { this.game.update(time); - window.requestAnimationFrame(this._onLoop); + this._timeOutID = window.requestAnimationFrame(this._onLoop); }, @@ -125,7 +132,7 @@ Phaser.RequestAnimationFrame.prototype = { } else { - window.cancelAnimationFrame; + window.cancelAnimationFrame(this._timeOutID); } this.isRunning = false;