Generate an array of Phaser.Types.Animations.AnimationFrame objects from a texture key and configuration object.
Generates objects with string based frame names, as configured by the given Phaser.Types.Animations.GenerateFrameNames.
It's a helper method, designed to make it easier for you to extract all of the frame names from texture atlases.
If you're working with a sprite sheet, see the generateFrameNumbers
method instead.
Example:
If you have a texture atlases loaded called gems
and it contains 6 frames called ruby_0001
, ruby_0002
, and so on,
then you can call this method using: this.anims.generateFrameNames('gems', { prefix: 'ruby_', start: 1, end: 6, zeroPad: 4 })
.
The end
value tells it to select frames 1 through 6, incrementally numbered, all starting with the prefix ruby_
. The zeroPad
value tells it how many zeroes pad out the numbers. To create an animation using this method, you can do:
this.anims.create({
key: 'ruby',
repeat: -1,
frames: this.anims.generateFrameNames('gems', {
prefix: 'ruby_',
end: 6,
zeroPad: 4
})
});
Please see the animation examples for further details.
name | type | arguments | description |
---|---|---|---|
key | string |
The key for the texture containing the animation frames. |
|
config | Phaser.Types.Animations.GenerateFrameNames | <optional> |
The configuration object for the animation frame names. |
The array of {@link Phaser.Types.Animations.AnimationFrame} objects.