Generate an array of Phaser.Types.Animations.AnimationFrame objects from a texture key and configuration object.
Generates objects with numbered frame names, as configured by the given Phaser.Types.Animations.GenerateFrameNumbers.
If you're working with a texture atlas, see the generateFrameNames
method instead.
It's a helper method, designed to make it easier for you to extract frames from sprite sheets.
If you're working with a texture atlas, see the generateFrameNames
method instead.
Example:
If you have a sprite sheet loaded called explosion
and it contains 12 frames, then you can call this method using:
this.anims.generateFrameNumbers('explosion', { start: 0, end: 11 })
.
The end
value tells it to stop after 12 frames. To create an animation using this method, you can do:
this.anims.create({
key: 'boom',
frames: this.anims.generateFrameNumbers('explosion', {
start: 0,
end: 11
})
});
Note that start
is optional and you don't need to include it if the animation starts from frame 0.
To specify an animation in reverse, swap the start
and end
values.
If the frames are not sequential, you may pass an array of frame numbers instead, for example:
this.anims.generateFrameNumbers('explosion', { frames: [ 0, 1, 2, 1, 2, 3, 4, 0, 1, 2 ] })
Please see the animation examples and GenerateFrameNumbers
config docs for further details.
name | type | arguments | description |
---|---|---|---|
key | string |
The key for the texture containing the animation frames. |
|
config | Phaser.Types.Animations.GenerateFrameNumbers | <optional> |
The configuration object for the animation frames. |
The array of {@link Phaser.Types.Animations.AnimationFrame} objects.