time and space

time and space

  • 1.7k
  • 31
  • 57k

Reducing repetitive asset loading

Aug 25 2011 1:43 PM
Let's say I have the following code to load a sprite into a gameobject:

bot1 = new GameObject[bots.maxBots];

for (short i = 0; i < bots.maxBots; i++)
  bot1[i] = new GameObject(
    Content.Load<Texture2D>("Sprites\\bot1"));

bots.Add(bot1);

Is there anyway I can substitute the bot number with a variable and put it in a loop (to create 100 bot1s, for example).  Something like this:

for (short i = 0; i < 100; i++
{
  bot + i = new GameObject[bots.maxBots];

  for (short i = 0; i < bots.maxBots; i++)
  bot + i[i] = new GameObject(
    Content.Load<Texture2D>("Sprites\\bot" + i));

  bots.Add(bot + i);
}


Answers (1)