Check if animation is playing

How do I check if an animation is playing?

I saw in the phaser API docs an isPlaying function under the ‘Animation’ section, and I tried doing something like:
if ( player.anims.isPlaying(‘walk’) ) {
// do something
}

I got an error that there’s no such function. Is there a way to check?

isPlaying returns only a boolean

Try this:

if (player.anims.isPlaying && player.anims.currentAnim.key === 'walk') {
  console.log('Player is walking')
}

or simply this:

if (player.anims.getCurrentKey() === 'walk') {
  console.log('Player is walking')
}
1 Like