I'm having trouble getting my keyboard to do what I want it to do.
this is at the top of my class
KeyboardState currentKey;
KeyboardState previousKey;
and this is in my update
currentKey = Keyboard.GetState();
if (checkKey(Keys.Left))
{
ship.shipPos.X -= 4;
}
if (checkKey(Keys.Right))
{
ship.shipPos.X += 4;
}
if (checkKey(Keys.Space))
{
addBullet(bulletFirePos);
}
previousKey = currentKey;
this is the checkKey class
public bool checkKey(Keys key)
{
return (currentKey.IsKeyDown(key) && previousKey.IsKeyUp(key));
}
The bullets are shooting fine, one bullet every press of the spacebar...although when I shoot the first bullet it stays right in front of the ship and doesn't move...but thats not a keyboard issue lol. The problem I'm having is with moving left and right. I have to repeatedly press the key to get the ship to move and that's not what I want. How do I change the method so that if I just hold the key down the ship moves?