Skip to content

Commit

Permalink
Multiple animation fixes in place.
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Sep 19, 2013
1 parent e938e41 commit 9e88da5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 52 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Version 1.0.5 (In progress)
* Added a pendingDelete property to Tween to stop tweens that were removed during a callback from causing update errors during the TweenManager loop.
* Added Group.length property.
* Added explicit x/y attributes to Phaser.Text to make it work with the camera system (thanks cocoademon).


* Fixed issue stopping multiple animations from playing, only the most recent would play (frames array was being overwritten, thanks Legrandk)

Version 1.0.4 (September 18th 2013)

Expand Down
36 changes: 36 additions & 0 deletions examples/animation/multiple anims.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
$title = "Multiple Animations";
require('../head.php');
?>

<script type="text/javascript">

(function () {

var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create });

function preload() {
game.load.atlas('bot', 'assets/misc/NumberSprite.png', 'assets/misc/NumberSprite.json');
}

function create() {

var bot = game.add.sprite(200, 200, 'bot');

bot.animations.add('num1', ['num10000','num10001','num10002','num10003','num10004','num10005'], 24, false, false);
bot.animations.add('num2', ['num20000','num20001','num20002','num20003','num20004','num20005'], 24, false, false);
bot.animations.add('num3', ['num30000','num30001','num30002','num30003','num30004','num30005'], 24, false, false);

// bot.animations.play('num1', 15, true);
bot.animations.play('num2', 15, true);
// bot.animations.play('num3', 15, true);

}

})();

</script>

<?php
require('../foot.php');
?>
Binary file added examples/assets/misc/NumberSprite.json
Binary file not shown.
Binary file added examples/assets/misc/NumberSprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 24 additions & 50 deletions src/animation/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,104 +9,78 @@
* An Animation instance contains a single animation and the controls to play it.
* It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
*
* @class Animation
* @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 {Mixed} 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.
* @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.<number>|Array.<string>)} 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.
*/
Phaser.Animation = function (game, parent, name, frameData, frames, delay, looped) {

/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;

/**
* A reference to the parent Sprite that owns this Animation.
* @property _parent
* @property {Phaser.Sprite} _parent - A reference to the parent Sprite that owns this Animation.
* @private
* @type {Phaser.Sprite}
*/
this._parent = parent;

/**
* The FrameData the Animation uses.
* @property _frameData
* @property {Phaser.FrameData} _frameData - The FrameData the Animation uses.
* @private
* @type {Phaser.FrameData}
*/
this._frameData = frameData;

/**
* The user defined name given to this Animation.
* @property name
* @public
* @type {String}
* @property {string} name - The user defined name given to this Animation.
*/
this.name = name;

/**
* @property _frames
* @property {object} _frames
* @private
* @type {Object}
*/
this._frames = frames;
this._frames = [];
this._frames = this._frames.concat(frames);

/**
* The delay in ms between each frame of the Animation.
* @property delay
* @public
* @type {Number}
* @property {number} delay - The delay in ms between each frame of the Animation.
*/
this.delay = 1000 / delay;

/**
* The loop state of the Animation.
* @property looped
* @public
* @type {Boolean}
* @property {boolean} looped - The loop state of the Animation.
*/
this.looped = looped;

/**
* The finished state of the Animation. Set to true once playback completes, false during playback.
* @property isFinished
* @public
* @type {Boolean}
* default true
* @property {boolean} isFinished - The finished state of the Animation. Set to true once playback completes, false during playback.
* @default
*/
this.isFinished = false;

/**
* The playing state of the Animation. Set to false once playback completes, true during playback.
* @property isPlaying
* @public
* @type {Boolean}
* default false
* @property {boolean} isPlaying - The playing state of the Animation. Set to false once playback completes, true during playback.
* @default
*/
this.isPlaying = false;

/**
* @property _frameIndex
* @property {number} _frameIndex
* @private
* @type {Number}
* default 0
* @default
*/
this._frameIndex = 0;

/**
* The currently displayed frame of the Animation.
* @property currentFrame
* @public
* @type {Phaser.Animation.Frame}
* @property {Phaser.Animation.Frame} currentFrame - The currently displayed frame of the Animation.
*/
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);

Expand Down

0 comments on commit 9e88da5

Please sign in to comment.