On 2015-07-02 04:12, Dominik Martinez wrote:
Hi everyone, I was hoping that someone could point me to some
tutorials for animating sprites in pygame. I did some googling, and
most of the methods I read about seem to either not extend well or act
more like a band-aid solution.
For example, in my case I have several sprite frames in different
directions that I would want to associate with the direction of travel
of the sprite (walking right, walking left, etc).
I was thinking of creating a separate "Animation" class to keep track
and execute the animation, but I want to see if there is a better or
more streamlined way of going about this.
Thanks!
Hi Dominik
It would helpful, if you wrote what methods you looked at and what you
exactly mean by 'seem to either not extend well or act more like a
band-aid solution'.
I think an animation class has been done many times in many ways. Its
probably the most common way to handle animations, but as you said
yourself, maybe not the only way to do it. But somewhere you have to
keep track of the current frame and have some logic to change it at the
right time.
Along time ago I wrote some tutorials on the subject. Please don't
believe all in it (I was a novice myself then), try out what you think
you can use and experiment with it. Here they are:
http://dr0id.homepage.bluewin.ch/pygame_tutorial04.html
For loading the images I recently wrote a spritesheetlib. At the moment
it can load spitesheets and has a limited support for animation
sequences (through properties you can set yourself). Try it out, maybe
it helps you to get some ideas how to handle the animations. Here you go:
https://bitbucket.org/dr0id/spritesheetlib/overview
Make sure you take a look at the wiki pages and especially to the method
'get_grouped_by_facing_and_action()' and how this works. Unfortunately I
had no time to write the section about how to add properties through the
generator yet, but editing a json string won't be that difficult.
I hope that helps you implement what you want. Feel free to ask questions.
~DR0ID