[XNA] Double Tap Key

Started by G_G, June 30, 2010, 08:18:21 pm

Previous topic - Next topic

G_G

I've been trying for at least 30 minutes on how to do this. I'm trying to make it where you need to double press a certain key real fast.

Example, you have to press space twice to avoid a fireball. Pretty much you have to press the key once, and you probably have 1 second to press it again or it fails. Any help is appreciated.

winkio

June 30, 2010, 08:21:50 pm #1 Last Edit: June 30, 2010, 09:06:45 pm by winkio
I made an input handler that will allow for this for one of my C# games, although it's for an XBOX controller, but the concept is similar, and it has a few more useful features.  Let me find it.

EDIT: well, I can't find the USB drive that the project was on, but this is the basic code:

float timeSincePressed;
bool doublePressed;

public void Update(GameTime gameTime)
{
    doublePressed = key.Pressed && (doublePressed  || timeSincePressed < 0.2f);
    if (key.Pressed)
       timeSincePressed = 0;
    else
       timeSincePressed += gameTime.ElapsedGameTime.TotalSeconds;
}


That should work, tell me if there are problems.