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

[pygame] Animation and event issues



This is incredibly weird. You can download my game here: http://www.box.net/shared/dti5isqh2s

The file is "hand2hand.py".

My game uses animation frames to activate "events". Basically, when an animation ends, a piece of code changes the state of the sprites and does some other things. The entire process is contained within the PlayerSprite.update and PlayerView.update methods, including advancing of frames.

But for some reason, when dynamically generated graphics are used for the images, the system fails to work. It is incredibly bizarre, since the system looks at lists, not the graphics themselves. Honestly, I find it hard to believe, but it's the only difference I can see between a working animation and a non-working animation.

To see the bug, run the game (link above). First, press the space bar. You should see the guy on the right swing his badly-drawn arm. That's the "right punch" animation. Everything goes as it should. This is because the punch is blocked, and so no other animations are started. But try holding "H" while pressing Space. This will cause the punch to happen in a different location, which causes the punch to hit the other player. notice that the guy on the left disappears; this is the "hurt" animation initiating, but not stopping. In the case of the "hurt" animation, no graphics were available to load, so a blank surface was created instead. The "hurt" animation should animate at a rate of 60 frames per second, which means the invisible image should only be seen for a fraction of a second, but as you can see, it just stays.

This makes no sense to me whatsoever. The graphics are loaded and generated in lines 885-970. As far as I can tell, if the graphics are forced to be dynamically generated, it should have no different effect than a normal image loaded properly. But I have tested removing all but one frame in the punch animation, and everything still works properly. It certainly doesn't seem like a giant list of images is being created, and even if it were, that still wouldn't explain why a very similar effect happens with left punch (left Shift key), though bizarrely the left arm doesn't disappear when Left Shift is pressed (which it should, since the left punch animation is being played).

So basically, I'm at a loss. I see no reason for this to happen. Any ideas? :-/