Note that there are some explanatory texts on larger screens.

plurals
  1. POXNA 4 - How to not spawn asteroids in same row?
    primarykey
    data
    text
    <p>I have asteroids spawning in my game with a timer on when they spawn and I want them to spawn one at a time. My problem is they all spawn in the same row, so as they increase speed going left there spawning on the asteroids that are already almost off the screen Here's what it looks like.</p> <p><a href="http://www.youtube.com/watch?v=9pKXZyzIpGs&amp;feature=youtu.be" rel="nofollow">http://www.youtube.com/watch?v=9pKXZyzIpGs&amp;feature=youtu.be</a></p> <p>Here's my update code.</p> <pre><code>namespace PixeBlastGame { public class GameUpdate { SpriteBatch spriteBatch; GameTime gameTime; Vector2 vPlayer = new Vector2(0, 720 / 2); Vector2 vAsteroid; Vector2 velocity; Random rand = new Random(); float spawnTimer; float spawnRate = 1; List&lt;Vector2&gt; Asteroids = new List&lt;Vector2&gt;(); public GameUpdate() { vAsteroid.Y = rand.Next(100, 680); vAsteroid.X = 1100; } public void Update(GameTime theTime) { gameTime = theTime; vPlayer.Y += velocity.Y; float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; spawnTimer += elapsed; if (spawnTimer &gt;= spawnRate) { Asteroids.Add(new Vector2(1000 ,rand.Next(0, 720))); spawnTimer = 0; } if (Keyboard.GetState().IsKeyDown(Keys.Down)) { velocity.Y = 5; } else if (Keyboard.GetState().IsKeyDown(Keys.Up)) { velocity.Y = -5; } else { velocity.Y = 0; } if (vPlayer.Y &gt; 630 )//+ Game1.tPlayer.Height) vPlayer.Y = 630; if (vPlayer.Y &lt; -10) //+ Game1.tPlayer.Height) vPlayer.Y = -10; } public void Draw(SpriteBatch theBatch) { spriteBatch = theBatch; foreach (Vector2 asteroid in Asteroids) //Draw each astroid { DrawAsteroid(asteroid.X, asteroid.Y); } spriteBatch.Begin(); spriteBatch.Draw(Game1.tPlayer, vPlayer, Color.White); spriteBatch.End(); } public void DrawAsteroid(float x, float y) { vAsteroid.X -= 5; vAsteroid.Y = y; spriteBatch.Begin(); spriteBatch.Draw(Game1.tAsteroid, vAsteroid, Color.White); spriteBatch.End(); } } } </code></pre> <p>If you need more code provided to help me, post a comment.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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