Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A quick overview of the problems I see that are causing your isses:</p> <ul> <li>You're checking if keys/buttons are pressed during your add, update, and draw methods.</li> <li>If a key isn't pressed, you're removing the item during an update and not drawing it during a draw.</li> </ul> <p>To accomplish what I think you're trying to accomplish, I'd do something along these lines (tailored and cleaned up for your needs, of course):</p> <pre><code>private void Update(GameTime gameTime) { // Only add a new projectile if Space or A is pressed if (currentKeyboardState.IsKeyDown(Keys.Space) || currentGamePadState.Buttons.A == ButtonState.Pressed) { AddProjectile(); // some method that adds a new projectile to 'projectiles' } // Update all existing projectiles, regardless of button press. // This will allow your projectiles to continue flying after they have been fired. for (int i = 0; i &lt; projectiles.Count; i++) { projectiles[i].Update(); if (projectiles[i].Dead) // check if projectiles[i] is out of bounds or has collided with something { projectiles.RemoveAt(i); i--; } } } private void Draw(GameTime gameTime) { // Draw all existing projectiles, regardless of button press. for (int i = 0; i &lt; projectiles.Count; i++) { projectiles[i].Draw(spriteBatch); } } </code></pre> <p>Your space bar or A button is only used to <em>fire</em> a new projectile. You want that projectile to fly until it hits something or flies off the side of the screen, and it shouldn't depend on whether you have a button pressed in order to do that. Neither should drawing the bullet.</p> <p>Make sense?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload