Jump to content
  • Advertisement
mrpeed

How should I go about blocking input to wait for an animation to finish

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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.

 

 

Edited by Kreative Pulp

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!