0

I have a for loop in which I declare positions of sprites. But they usually get spawned near each other and it looks horrible. Using such functions as dbWait(1000); freezes all the sprites with it so it's not a solution.

Is there a way to make a gap between spawning?

for(int i=20;i<=25;i++){
    dbSprite(i,dbRnd(500),dbRnd(90)+400,20);
    dbHideSprite(i);
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
RnD
  • 1,019
  • 5
  • 23
  • 49

1 Answers1

0
int spritesToSpawn = 25;

while (LoopGDK ())
{
 if (spritesToSpawn)
  if (waitToSpawn <= 0)
  {
    dbSprite (i, dbRnd (500), dbRnd(90)_400, 20);
    waitToSpawn = SPAWNING_DELAY;
    --spritesToSpawn;
  }
  else
    --waitToSpawn;

 ...

 dbSync();
}

That is, the trick is to make use of that main loop. Let it go about its business, making use of it to spawn whenever you're ready for another.

Topological Sort
  • 2,733
  • 2
  • 27
  • 54