2
votes

Is it possible to use an animation I made with aseprite in python, pygame? It's just an animation of 2 images of a rat running, and I want it to be an object where I can control its X and Y coordinates.

I find this more convenient than making the animation in python, pygame, primarily because the speed of the animation is determined by me once and stays so. All i have to do is to make it in aseprite, export, (and if possible) - load it into a variable in python-pygame, say ratRun which will be an object I can use and manipulate its X and Y variables the way I need to.

PS the possible codecs to export the animation from aseprite are: ase aseprite bmp flc fli gif ico jpeg jpg pcx png tga

png works well with pygame but it's only an image file. Another form of my original question perhaps is if pygame can support an animation file also.

1
The latest version of Aseprite can also export json data with a spritesheet. It is possible to write python code that will read all the timing and offset information. If I have time I will write it. - Samie Bencherif
For my own project I found pyglet very helpful. See this page about animating from spritesheets: pyglet.readthedocs.io/en/latest/modules/image/animation.html - Samie Bencherif

1 Answers

0
votes

This is not possible. In http://www.pygame.org/docs/ref/image.html it has a list of image types that can be loaded via Pygame. Here is the list (emphasis added):

  • JPG
  • PNG
  • GIF (non animated)
  • BMP
  • PCX
  • TGA (uncompressed)
  • TIF
  • LBM (and PBM)
  • PBM (and PGM, PPM)
  • XPM

Aseprite can only export in gif, sequence of pngs, or ase. Pygame cannot use .ase or animated gifs (an animated gif only shows the first frame of animation), and a sequence of pngs, well, that's just a list of images. To do animations in Pygame, you have to have multiple images, and have your program iterate through them. As far as I know, Pygame does not support any animated images.

Everybody does their animations differently, but for games, people almost never use gifs. To see some ways other people do their animations, you can go to http://pygame.org and download some contributed programs to see how they do their animations. You can look at the source code if it is a .py file.

Using gifs can cause many potential problems in programs. If there is even a slight differing of the framerate (which there almost always is), this will throw the timing for the animation completely off. Also, sprites are erased and redrawn, either every loop or whenever it is moved, depending on how you program it. This would cause even more issues.

Animations may seem difficult at first, but, with practice, it eventually becomes second nature.