1
\$\begingroup\$

I'm making a game sprite, with animations for transitioning to different states, such as idle, sleeping, etc. I'm wondering what the most efficient way to play the animations is. As of now, I have a couple of ideas:

  • store all frames as separate PNG images, and display only the frames for the current state (e.g. play frames 1-5 for idle, 5-10 for transitioning, 10-15 for sleeping)
  • make the animations into GIFs and play the one corresponding to the current state.
  • merge them all into a spritesheet.

Please let me know which would be the best approach, or if there's a better way to do things. I'm new to handling images and animation with code, so I'm not sure what the advantages and disadvantages are. Thanks!

In case the information helps anyone, I'm planning to use Python for this (although I could also do Java or C++, if there are good solutions in those languages), and the sprite image size isn't large, it's pixel art.

\$\endgroup\$
2

1 Answer 1

0
\$\begingroup\$

Storing all frames from every image as one large image allows for the hardware to use the same material/shader/texture for every animation and avoids context switching.

Then it's just a matter of calculating a frame's bounds in UV space (or pixel space if the graphics library you're using doesn't support UVs) given a frame index or its coordinates.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .