Skip to content

Instantly share code, notes, and snippets.

@kenpower
Created November 8, 2012 12:54
Show Gist options
  • Select an option

  • Save kenpower/4038636 to your computer and use it in GitHub Desktop.

Select an option

Save kenpower/4038636 to your computer and use it in GitHub Desktop.
Create and use a List
//creat a list of sprite objects
List<Sprite> sprites=new List<Sprite>();
...
//populate a list of sprite objects
for (int i = 0; i < 50; i++)
{
Sprite s = new Sprite();
s.SetRandomPosition(r,BattleFieldRect);
s.SetRandomVelocity(r);
sprites.Add(s);
}
...
//draw all the lements in a list
spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, radarTrans);
foreach (Sprite s in sprites)
s.Draw(gameTime, spriteBatch, true);
spriteBatch.End();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment