I am working on a game tutorial with XNA but I am modifying it slightly. Instead of adding projectiles to an array based on a duration, I am trying to add them to the array by pressing the SpaceBar. So this way the user has some control over firing the missiles.
if (currentKeyboardState.IsKeyDown(Keys.Space))
{
AddProjectile(player.Position + new Vector2(player.Width / 2, 0));
}
private void AddProjectile(Vector2 position)
{
Projectile projectile = new Projectile();
projectile.Initialize(GraphicsDevice.Viewport, projectileTexture, position);
projectiles.Add(projectile);
}
However I am running into a minor problem. Since I am using the method IsKeyDown() missiles will be added to the projectiles array until the space bar is released. Is there a method that will register a key press rather than IsKeyDown().

Add a field that keeps track of the previous keyboard state
You will update this state at the end of the
Update. You can now do edge detection:The thinking is: If on previous pass the key had not been pressed, but now it is pressed, do this action.