How to access the next Frame?

Hi, What is the best way to access the next frame of a sprite or get the total frames of a sprite?

var frames = sprite.texture.getFrameNames();
var next = frames[1 + frames.indexOf(] || frames[0];

@brenodp do you mean the next frame in an animation on a Sprite?

Yes. I do.


Use Sprite.anims.getTotalFrames() to get the total number of frames in the currently loaded animation on a Sprite.

To get the next frame, assuming an animation has been loaded, you can do Sprite.anims.currentFrame.nextFrame, but you may want to check isLast first, because if so, nextFrame will always be null.

Great. I will try