diff --git a/README.md b/README.md index 00c900a4..7af998fd 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Version 1.0.7 (in progress in the dev branch) * Fixed issue in Animation.play where the given frameRate and loop values wouldn't overwrite those set on construction. * Added Animation.paused - can be set to true/false. * New: Phaser.Animation.generateFrameNames - really useful when creating animation data from texture atlases using file names, not indexes. +* Added Sprite.play as a handy short-cut to play an animation already loaded onto a Sprite. * TODO: addMarker hh:mm:ss:ms diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index d10f366a..b0dc29a4 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -470,6 +470,25 @@ Phaser.Sprite.prototype.getBounds = function(rect) { } +/** +* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add() +* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself. +* +* @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. +* @return {Phaser.Animation} A reference to playing Animation instance. +*/ +Phaser.Sprite.prototype.play = function (name, frameRate, loop) { + + if (this.animations) + { + this.animations.play(name, frameRate, loop); + } + +} + Object.defineProperty(Phaser.Sprite.prototype, 'angle', { get: function() {