Lets say I have a character with a shooting animation that plays every time I hit the space key. I need to block input to assure that the animation finishes before another action is taken. What is a common approach to doing this? Right now, I'm using a variable that is a set to the total number of seconds the animation is. When the variable is zero player input is allowed again. Is there a better way? I'm using Python and Pygame for a 2D game.
How should I go about blocking input to wait for an animation to finish
No, that's pretty much the standard way to rate-limit anything. You can store it as "time left" (relative) or "time the command becomes available" (absolute) but that's more a preference thing. Just don't mix the two, that gets confusing fast.
Hi,
Ideally every animation system would have callbacks which can be registered. If you are writing your own system then you should allow a function callback to be registered along with the animation and allow the callback to called at a particular point in animation.
You can use this function callback to actually decide whether to set any state or to allow input or to play a particular sound etc. Don't do it with seconds separately as that will cause other bugs which will soon become harder to fix.
Hi ,
When you draw animation , you do it by drawing each frame.So you know how many frames you have in animation and the current one.From this you know when the animation is over and like Kreative Pulp said you can call a callback or just have some if statement.But I suggest you read about states and how to use this concept.You can have a concept of your character being responsive or not.