Animation.next will advance to the next frame in the animation, even if it's not currently playing. You can optionally define the number of frames to advance, but the default is 1. This is also aliased from the AnimationManager, so you can do Sprite.animations.next().

Animation.previous will rewind to the previous frame in the animation, even if it's not currently playing. You can optionally define the number of frames to rewind, but the default is 1. This is also aliased from the AnimationManager, so you can do `Sprite.animations.previous()`.
This commit is contained in:
photonstorm 2014-07-03 16:23:36 +01:00
parent e4536f9999
commit 14109aeeb1
4 changed files with 126 additions and 0 deletions

View file

@ -128,6 +128,8 @@ Version 2.0.6 - "Jornhill" - -in development-
* Internal child movements in Group (such as bringToTop) now uses the new `silent` parameter to avoid the child emitting incorrect Group addition and deletion events.
* Camera.updateTarget has had a make-over and now is a lot smoother under certain conditions (thanks @tjkopena, fix #966)
* Signal.removeAll now has a new `context` parameter. If specified only listeners matching the given context are removed (thanks @lucbloom for the idea, #880)
* Animation.next will advance to the next frame in the animation, even if it's not currently playing. You can optionally define the number of frames to advance, but the default is 1. This is also aliased from the AnimationManager, so you can do `Sprite.animations.next()`.
* Animation.previous will rewind to the previous frame in the animation, even if it's not currently playing. You can optionally define the number of frames to rewind, but the default is 1. This is also aliased from the AnimationManager, so you can do `Sprite.animations.previous()`.
### Bug Fixes

4
build/phaser.d.ts vendored
View file

@ -1111,9 +1111,11 @@ declare module Phaser {
complete(): void;
destroy(): void;
static generateFrameNames(prefix: string, start: number, stop: number, suffix?: string, zeroPad?: number): string[];
next(quantity?: number): void;
onPause(): void;
onResume(): void;
play(frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
previous(quantity?: number): void;
restart(): void;
setFrame(frameId?: any, useLocalFrameIndex?: boolean): void;
stop(resetFrame?: boolean, dispatchComplete?: boolean): void;
@ -1139,7 +1141,9 @@ declare module Phaser {
add(name: string, frames?: any[], frameRate?: number, loop?: boolean, useNumericIndex?: boolean): Phaser.Animation;
destroy(): void;
getAnimation(name: string): Phaser.Animation;
next(quantity?: number): void;
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
previous(quantity?: number): void;
refreshFrame();
stop(name?: string, resetFrame?: boolean): void;
update(): boolean;

View file

@ -413,6 +413,94 @@ Phaser.Animation.prototype = {
},
/**
* Advances by the given number of frames in the Animation, taking the loop value into consideration.
*
* @method Phaser.Animation#next
* @param {number} [quantity=1] - The number of frames to advance.
*/
next: function (quantity) {
if (typeof quantity === 'undefined') { quantity = 1; }
var frame = this._frameIndex + quantity;
if (frame >= this._frames.length)
{
if (this.loop)
{
frame %= this._frames.length;
}
else
{
frame = this._frames.length - 1;
}
}
if (frame !== this._frameIndex)
{
this._frameIndex = frame;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
if (this.currentFrame)
{
this._parent.setFrame(this.currentFrame);
if (this._parent.__tilePattern)
{
this._parent.__tilePattern = false;
this._parent.tilingTexture = false;
}
}
}
},
/**
* Moves backwards the given number of frames in the Animation, taking the loop value into consideration.
*
* @method Phaser.Animation#previous
* @param {number} [quantity=1] - The number of frames to move back.
*/
previous: function (quantity) {
if (typeof quantity === 'undefined') { quantity = 1; }
var frame = this._frameIndex - quantity;
if (frame < 0)
{
if (this.loop)
{
frame = this._frames.length + frame;
}
else
{
frame++;
}
}
if (frame !== this._frameIndex)
{
this._frameIndex = frame;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
if (this.currentFrame)
{
this._parent.setFrame(this.currentFrame);
if (this._parent.__tilePattern)
{
this._parent.__tilePattern = false;
this._parent.tilingTexture = false;
}
}
}
},
/**
* Cleans up this animation ready for deletion. Nulls all values and references.
*

View file

@ -298,6 +298,38 @@ Phaser.AnimationManager.prototype = {
},
/**
* Advances by the given number of frames in the current animation, taking the loop value into consideration.
*
* @method Phaser.AnimationManager#next
* @param {number} [quantity=1] - The number of frames to advance.
*/
next: function (quantity) {
if (this.currentAnim)
{
this.currentAnim.next(quantity);
this.currentFrame = this.currentAnim.currentFrame;
}
},
/**
* Moves backwards the given number of frames in the current animation, taking the loop value into consideration.
*
* @method Phaser.AnimationManager#previous
* @param {number} [quantity=1] - The number of frames to move back.
*/
previous: function (quantity) {
if (this.currentAnim)
{
this.currentAnim.previous(quantity);
this.currentFrame = this.currentAnim.currentFrame;
}
},
/**
* Returns an animation that was previously added by name.
*