carson Posted June 5, 2015 Share Posted June 5, 2015 (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);player.animations.play('run');// pause animation for a momentfunction freeze() { player.animations.currentAnim.pause(); game.time.events.add(500, function(){ player.animations.currentAnim.resume(); }, game);}Things I have already tried: Using stop() and play() - this just starts the animation from the beginningSetting currentAnim.paused = true - doesn't seem to have any effectUsing setFrame() and play() together - just plays from the beginning Any help would be greatly appreciated! Link to comment Share on other sites More sharing options...
frenetikm Posted June 5, 2015 Share Posted June 5, 2015 Hi, 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.animations.stop();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;player.animations.stop();switch(currentFrame) { case 0: player.animations.play('run0'); break; case 1: player.animations.play('run1'); break; case 2: player.animations.play('run2'); break; case 3: player.animations.play('run3'); break; default: player.animations.play('run0');} didn't test it, but I think it probably works Link to comment Share on other sites More sharing options...
lucidmoon Posted June 7, 2015 Share Posted June 7, 2015 Hi, from what i read from the phaser documentation (http://phaser.io/docs/Phaser.Animation.html/Phaser.AnimationManager.html#paused) the answer for your problem is actually simple: to freeze the animation, use:player.animations.paused = true;to resume, use:player.animations.paused = false;hope this help ForgeableSum 1 Link to comment Share on other sites More sharing options...
darkraziel Posted October 8, 2015 Share Posted October 8, 2015 I just wanted to confirm that lucidmoon solution works perfectly. Thanks =) Link to comment Share on other sites More sharing options...
Recommended Posts