How to pause and resume an animation

Recommended Posts

(Edit): Short version: As simple as the title sounds. How can you pause an animation and then resume it from that same frame?



Long version:

I am completely stumped with something I thought would be very simple. 


I have an animation that plays. When an event occurs (I don't know when it will happen ahead of time), the animation needs to pause on its current frame. Then, I need to be able to resume the animation from that frame. I have searched all around and can't seem to find a simple solution to this. 


Here's what I want to do (but this doesn't work):

var player = game.add.spritesheet('hero', 'hero.png', 32, 32);player.animations.add('run', [0,1,2,3], 12, true);'run');// pause animation for a momentfunction freeze() {     player.animations.currentAnim.pause();, function(){          player.animations.currentAnim.resume();     }, game);}

Things I have already tried: 

  • Using stop() and play() - this just starts the animation from the beginning
  • Setting currentAnim.paused = true - doesn't seem to have any effect
  • Using setFrame() and play() together - just plays from the beginning


Any help would be greatly appreciated!

Share this post

Link to post
Share on other sites



For me you can't start an animation from a distinct frame.


you defined your animation from frame 0 to 3, you can't start from another frame than 0


the easiest is to do:

player.frame = 0; // define the current frame



for what you want you can add 4 animations:

[0,1,2,3], 1,2,3,0], etc.

named 'run0', 'run1', etc.


var currentFrame = player.frame;


switch(currentFrame) {

  case 0:'run0');


  case 1:'run1');


  case 2:'run2');


  case 3:'run3');





didn't test it, but I think it probably works

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.