Phaser API Documentation

  Version: 
play(key, [ignoreIfPlaying])

Description:

Start playing the given animation on this Plane.

Animations in Phaser can either belong to the global Animation Manager, or specifically to this Plane.

The benefit of a global animation is that multiple Game Objects can all play the same animation, without having to duplicate the data. You can just create it once and then play it on any animating Game Object.

The following code shows how to create a global repeating animation. The animation will be created from all of the frames within the sprite sheet that was loaded with the key 'muybridge':

var config = {
    key: 'run',
    frames: 'muybridge',
    frameRate: 15,
    repeat: -1
};

//  This code should be run from within a Scene:
this.anims.create(config);

However, if you wish to create an animation that is unique to this Plane, and this Plane alone, you can call the Animation.create method instead. It accepts the exact same parameters as when creating a global animation, however the resulting data is kept locally in this Plane.

With the animation created, either globally or locally, you can now play it on this Plane:

const plane = this.add.plane(...);
plane.play('run');

Alternatively, if you wish to run it at a different frame rate for example, you can pass a config object instead:

const plane = this.add.plane(...);
plane.play({ key: 'run', frameRate: 24 });

When playing an animation on a Plane it will first check to see if it can find a matching key locally within the Plane. If it can, it will play the local animation. If not, it will then search the global Animation Manager and look for it there.

If you need a Plane to be able to play both local and global animations, make sure they don't have conflicting keys.

See the documentation for the PlayAnimationConfig config object for more details about this.

Also, see the documentation in the Animation Manager for further details on creating animations.

Parameters:

name type arguments Default description
key string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig

The string-based key of the animation to play, or an Animation instance, or a PlayAnimationConfig object.

ignoreIfPlaying boolean <optional> false

If an animation is already playing then ignore this call.

Returns:
Description:

This Game Object.

Since: 3.60.0