If you want your sprites at the same random positions all the time and still clear your viewport (for example, you can display different content), you can simply reset the random seed of each frame with the same value
protected override void Draw(GameTime gameTime) { randomera = new Random(seed); GraphicsDevice.Clear(Color.White); spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); if (counter < 10) { for (int i = 0; i < 10; i++) { spriteBatch.Draw(turtleTexture, new Vector2(randomera.Next(600), randomera.Next(400)), Color.Black); counter++; } } spriteBatch.End(); base.Draw(gameTime); }
where the seed must be randomly generated in your Initialize() method and will not be changed after it.
You can also simply initialize the list using predefined coordinates:
List<Vector2> coords = Enumerable.Range(0, 10).Select(i => new Vector2(randomera.Next(600), randomera.Next(400)).ToList();
and use this list in your drawing procedure:
for (int i = 0; i < 10; i++) { spriteBatch.Draw(turtleTexture, coords[i], Color.Black); }
source share