EDIT: Haha, simul-posted. My post is just a long-winded elaboration of Daaark's post.
Basically, you're going to need a timer variable for every key/button that you'll want to allow for this time delay. What I've done is created an InputState struct that looks like this:
struct InputState
{
public bool Previous; // True if button was pressed last frame
public bool Current; // True if button is pressed this frame
public bool Pressed; // True for each frame of delayed input
public int Timer; // Number of milliseconds before next delayed input
}
Then, I created an Input class that has an InputState for every key/button. I also declare two constant values, REPEAT_DELAY and REPEAT_INTERVAL. REPEAT_DELAY is the number of milliseconds between the initial button press and the first repeat, and REPEAT_INTERVAL is the number of milliseconds between each repeated input. On each Update call to the game, I update every InputState in the Input class like this:
inputState[button].Previous = inputState[button].Current;
inputState[button].Current = gamePadState.IsButtonDown(button);
if (inputState[button].Current)
{
if (inputState[button].Previous)
{
inputState[button].Timer -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;
if (inputState[button].Timer < 0)
{
inputState[button].Pressed = true;
inputState[button].Timer += REPEAT_INTERVAL;
}
else
{
inputState[button].Pressed = false;
}
}
else
{
inputState[button].Pressed = true;
inputState[button].Timer = REPEAT_DELAY;
}
}
else
{
inputState[button].Pressed = false;
inputState[button].Timer = 0;
}
Now, just check inputState[button].Pressed if you want to detect delayed repeated input, or simply check inputState[button].Current if you want to see if the button is being held down. Hopefully, this will give you a rough idea of how I go about solving this problem.
Previously known as "Rainault".
Twitter -
me,
Jade Vault GamesAnnouncing
ASCII Quest, a Roguelike under development for Xbox LIVE Indie Games