I am currently developing in XNA/C#.
When the user presses a key (Keys.Right), I need to move an object.
I want this to happen
- when the user presses the key
- after 1 second while the user is holding the key and then every .25 seconds.
I already implemented the first one:
_kbOld = _kbNew;
_kbNew = _kb.GetState();
if(_kbNew.IsKeyDown(Keys.Right) &&
_kbOld.IsKeyUp(Keys.Right))
{
//Do something
}
How would I do the other actions?
I had the following ideas:
-
A
Queue<KeyboardState>, keeping track of the lastKeyboardStates -
Saving the time the key was last pressed and when it was released (
GameTime)
It should work like text input in Windows: When you hold a letter, it will repeat after a certain amount of time.
Which way should I use? Do you have other ideas?
Thanks in advance!
I would simply store the last push time, like you suggested: