A SpriteAnimation object contains a series of images (p5.Image objects) that can be displayed sequentially.
A sprite can have multiple labeled animations, see Sprite.addAnimation and Sprite.changeAnimation, but you can also create animations that can be used without being added to a sprite first.
An animation can be created either from a list of images or sequentially numbered images. p5.play will try to detect the sequence pattern.
For example if the image file path is "image1.png" and the last frame index is 3 then "image2.png" and "image3.png" will be loaded as well.
Table of Contents
let shapeShifter = new SpriteAnimation("dog.png", "cat.png", "snake.png"); let walking = new SpriteAnimation("walking0001.png", 5);
Draws the animation at coordinate x and y. Updates the frames automatically.
Returns the current frame image as p5.Image.
Current frame image
Plays the animation forward or backward toward a target frame.
Frame number destination (starts from 0)
Goes to the next frame and stops.
Plays the animation, starting from the specified frame.
Goes to the previous frame and stops.
Plays the animation backwards. Equivalent to ani.goToFrame(0)
Stops the animation.
The index of the current frame that the animation is on.
True if frame changed during the last draw cycle
Delay between frames in number of draw cycles. If set to 4 the framerate of the animation would be the sketch framerate divided by 4 (60fps = 15fps)
Array of frames (p5.Image)
If set to false the animation will stop after reaching the last frame
The name of the animation
Object x and y keys
The offset is how far the animation should be placed from the location it is played at.
offset.x = 16;
True if the animation is currently playing.