Animation.killOnComplete added and fixed a few issues in the Tanks game.

This commit is contained in:
photonstorm
2013-10-09 13:36:57 +01:00
parent 29acf7fb4b
commit f10f9324ad
5 changed files with 38 additions and 16 deletions
+19 -2
View File
@@ -59,6 +59,11 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope
*/
this.looped = looped;
/**
* @property {boolean} looped - The loop state of the Animation.
*/
this.killOnComplete = false;
/**
* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
* @default
@@ -120,10 +125,11 @@ Phaser.Animation.prototype = {
* @method Phaser.Animation#play
* @memberof Phaser.Animation
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param {boolean} [loop=null] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
* @return {Phaser.Animation} - A reference to this Animation instance.
*/
play: function (frameRate, loop) {
play: function (frameRate, loop, killOnComplete) {
if (typeof frameRate === 'number')
{
@@ -137,6 +143,12 @@ Phaser.Animation.prototype = {
this.looped = loop;
}
if (typeof killOnComplete !== 'undefined')
{
// Remove the parent sprite once the animation has finished?
this.killOnComplete = killOnComplete;
}
this.isPlaying = true;
this.isFinished = false;
@@ -298,6 +310,11 @@ Phaser.Animation.prototype = {
this._parent.events.onAnimationComplete.dispatch(this._parent, this);
}
if (this.killOnComplete)
{
this._parent.kill();
}
}
};
+6 -5
View File
@@ -101,7 +101,7 @@ Phaser.AnimationManager.prototype = {
// If they didn't set the useNumericIndex then let's at least try and guess it
if (typeof useNumericIndex === 'undefined')
{
if (frames[0] && typeof frames[0] === 'number')
if (frames && frames[0] && typeof frames[0] === 'number')
{
useNumericIndex = true;
}
@@ -173,10 +173,11 @@ Phaser.AnimationManager.prototype = {
* @method Phaser.AnimationManager#play
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param {boolean} [loop=null] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
* @return {Phaser.Animation} A reference to playing Animation instance.
*/
play: function (name, frameRate, loop) {
play: function (name, frameRate, loop, killOnComplete) {
if (this._anims[name])
{
@@ -184,13 +185,13 @@ Phaser.AnimationManager.prototype = {
{
if (this.currentAnim.isPlaying == false)
{
return this.currentAnim.play(frameRate, loop);
return this.currentAnim.play(frameRate, loop, killOnComplete);
}
}
else
{
this.currentAnim = this._anims[name];
return this.currentAnim.play(frameRate, loop);
return this.currentAnim.play(frameRate, loop, killOnComplete);
}
}
+4 -3
View File
@@ -659,14 +659,15 @@ Phaser.Sprite.prototype.bringToTop = function() {
* @method play
* @param {String} name The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param {number} [frameRate=null] The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param {Boolean} [loop=null] Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {boolean} [loop=false] Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
* @return {Phaser.Animation} A reference to playing Animation instance.
*/
Phaser.Sprite.prototype.play = function (name, frameRate, loop) {
Phaser.Sprite.prototype.play = function (name, frameRate, loop, killOnComplete) {
if (this.animations)
{
this.animations.play(name, frameRate, loop);
this.animations.play(name, frameRate, loop, killOnComplete);
}
}