Skip to content

Commit 202c6c9

Browse files
committed
Added nextFrame and previousFrame to the Animation component
1 parent 0ac7dec commit 202c6c9

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
* `BlendModes.XOR` is a new Canvas-only blend mode, that allows you to use the `xor` composite operation when rendering Game Objects.
4242
* `RenderTexture.erase` is a new method that will take an object, or array of objects, and draw them to the Render Texture using an ERASE blend mode, resulting in them being removed from the Render Texture. This is really handy for making a bitmap masked texture in Canvas or WebGL (without using an actual mask), or for 'cutting away' part of a texture.
4343
* There is a new boolean Game Config property called `customEnvironment`. If set to `true` it will skip the internal Feature checks when working out which type of renderer to create, allowing you to run Phaser under non-native web environments. If using this value, you _must_ set an explicit `renderType` of either CANVAS or WEBGL. It cannot be left as AUTO. Fix #4166 (thanks @jcyuan)
44+
* `Animation.nextFrame` will advance an animation to the next frame in the sequence instantly, regardless of the animation time or state. You can call this on a Sprite: `sprite.anims.nextFrame()` (thanks rgk25)
45+
* `Animation.previousFrame` will set an animation to the previous frame in the sequence instantly, regardless of the animation time or state. You can call this on a Sprite: `sprite.anims.previousFrame()` (thanks rgk25)
4446

4547
### Updates
4648

src/gameobjects/components/Animation.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,50 @@ var Animation = new Class({
10191019
}
10201020
},
10211021

1022+
/**
1023+
* Advances the animation to the next frame, regardless of the time or animation state.
1024+
* If the animation is set to repeat, or yoyo, this will still take effect.
1025+
*
1026+
* Calling this does not change the direction of the animation. I.e. if it was currently
1027+
* playing in reverse, calling this method doesn't then change the direction to forwards.
1028+
*
1029+
* @method Phaser.GameObjects.Components.Animation#nextFrame
1030+
* @since 3.16.0
1031+
*
1032+
* @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to.
1033+
*/
1034+
nextFrame: function ()
1035+
{
1036+
if (this.currentAnim)
1037+
{
1038+
this.currentAnim.nextFrame(this);
1039+
}
1040+
1041+
return this.parent;
1042+
},
1043+
1044+
/**
1045+
* Advances the animation to the previous frame, regardless of the time or animation state.
1046+
* If the animation is set to repeat, or yoyo, this will still take effect.
1047+
*
1048+
* Calling this does not change the direction of the animation. I.e. if it was currently
1049+
* playing in forwards, calling this method doesn't then change the direction to backwards.
1050+
*
1051+
* @method Phaser.GameObjects.Components.Animation#previousFrame
1052+
* @since 3.16.0
1053+
*
1054+
* @return {Phaser.GameObjects.GameObject} The Game Object this Animation Component belongs to.
1055+
*/
1056+
previousFrame: function ()
1057+
{
1058+
if (this.currentAnim)
1059+
{
1060+
this.currentAnim.previousFrame(this);
1061+
}
1062+
1063+
return this.parent;
1064+
},
1065+
10221066
/**
10231067
* Sets if the current Animation will yoyo when it reaches the end.
10241068
* A yoyo'ing animation will play through consecutively, and then reverse-play back to the start again.

0 commit comments

Comments
 (0)