[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Animating sprites with pygame



Hi dominik

Âhere is some example of sprite animation as well as sprite animation with AI ( in a small way :-) )
Hope this code helps you.

http://soft.diliupg.com/python-scripts-game-code/

Also below is a fabulous site which is a good place to start

http://www.petercollingridge.co.uk/projects

On Thu, Jul 2, 2015 at 11:18 PM, DR0ID <dr0id@xxxxxxxxxx> wrote:
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



--
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************