Learning how to start an animation is one thing, pausing it is another. When it’s game over, or if we decide to include a pause option, we might opt to pause one or all of our animations.
In Phaser, we can call
exampleSprite.anims.pause() on the sprite to put a pause on its animation.
We can also call
this.anims.pauseAll() to pause all animations in a Scene.
Let’s try out these convenient methods in our own game.
We’ve included animated snowmen in the middle of the main platform. We also added in an Overlap object that checks when Codey comes in contact with a snowman, it works very similarly to a Collider object except it allows the sprites to overlap.
The Overlap object is in the
create() method. Inside the callback function of the Overlap object, pause the animation of the snowman when the two sprites come into contact. Do this by calling
Test out what happens in the game after you clear this checkpoint!
We’ve paused one snowman animation, but let’s see what happens when we pause all the animations!
Inside the same callback function of the previous step, call