OptionalanimationThe speed that the AnimatedSprite will play at. Higher is faster, lower is slower.
// Create an AnimatedSprite with a slower animation speed
const animation = new AnimatedSprite({
textures: [Texture.from('frame1.png'), Texture.from('frame2.png')],
animationSpeed: 0.5 // Slower animation
});
// Update the animation speed to make it faster
animation.animationSpeed = 2; // Faster animation
OptionalautoWhether to start the animation immediately on creation.
If set to true, the animation will start playing as soon as the
AnimatedSprite is created.
If set to false, you will need to call the play method to start the animation.
// Create an AnimatedSprite that starts playing immediately
const animation = new AnimatedSprite({
textures: [Texture.from('frame1.png'), Texture.from('frame2.png')],
autoPlay: true
});
// Create an AnimatedSprite that does not start playing immediately
const animation = new AnimatedSprite({
textures: [Texture.from('frame1.png'), Texture.from('frame2.png')],
autoPlay: false
});
animation.play(); // Start the animation manually
OptionalautoWhether to use Ticker.shared to auto update animation time.
This is useful for animations that need to be updated every frame.
If set to false, you will need to manually call the update method
to update the animation.
OptionalloopWhether or not the animation repeats after playing.
OptionalonUser-assigned function to call when an AnimatedSprite finishes playing.
OptionalonUser-assigned function to call when an AnimatedSprite changes which texture is being rendered.
animation.onFrameChange = (currentFrame) => {
// Updated!
console.log('Current frame:', currentFrame);
};
OptionalonUser-assigned function to call when loop is true,
and an AnimatedSprite is played and loops around to start again.
An array of Texture or frame objects that make up the animation.
// Create an AnimatedSprite with an array of textures
const animation = new AnimatedSprite({
textures: [
Texture.from('frame1.png'),
Texture.from('frame2.png'),
Texture.from('frame3.png')
]
});
* // Create an AnimatedSprite with an array of frame objects
const animation = new AnimatedSprite({
textures: [
{ texture: Texture.from('frame1.png'), time: 100 },
{ texture: Texture.from('frame2.png'), time: 200 },
{ texture: Texture.from('frame3.png'), time: 300 }
]
});
AnimatedSpriteFrames For the type of the textures array
OptionalupdateUpdate anchor to [Texture's defaultAnchor]Texture#defaultAnchor when frame changes.
Useful with [sprite sheet animations]Spritesheet#animations created with tools. Changing anchor for each frame allows to pin sprite origin to certain moving feature of the frame (e.g. left foot).
Enabling this will override any previously set anchor on each frame change.
// Create an AnimatedSprite with updateAnchor enabled
const animation = new AnimatedSprite({
textures: [Texture.from('frame1.png'), Texture.from('frame2.png')],
updateAnchor: true
});
Texture#defaultAnchor For the default anchor of the texture
Constructor options used for
AnimatedSpriteinstances. Allows configuration of animation playback, speed, and texture frames.Example
See