How can i have two loops going at once?
Root / Programming Questions / [.]
Jacklack3Created:
Instead of making two loops that each do one thing, you should instead think about one loop which does two things (or more). Basically everything in a game can go in one loop.
For instance, you can do something like:
WHILE WHATEVER CHANGE SPRITE PLAY SOUND WENDIf you only want to play the sound sometimes, you can make a conditional:
WHILE WHATEVER CHANGE SPRITE IF SHOULDPLAY THEN PLAY SOUND WENDLet's say that different sprites play different sounds. You could just use the character ID for the sprite you're setting as part of the check for playing a sound. The bottom line is: don't try to make multiple simultaneous loops. Many things can happen in a loop; you don't have to make a new one for each thing.
Instead of making two loops that each do one thing, you should instead think about one loop which does two things (or more). Basically everything in a game can go in one loop. For instance, you can do something like:Well the thing is that i want the fan sprite to change every 1 ms, but it would be to hard to go ahead and make the perfect timing in one loop. Plus i dont see howWHILE WHATEVER CHANGE SPRITE PLAY SOUND WENDIf you only want to play the sound sometimes, you can make a conditional:WHILE WHATEVER CHANGE SPRITE IF SHOULDPLAY THEN PLAY SOUND WENDLet's say that different sprites play different sounds. You could just use the character ID for the sprite you're setting as part of the check for playing a sound. The bottom line is: don't try to make multiple simultaneous loops. Many things can happen in a loop; you don't have to make a new one for each thing.
whilewould help.
You only want to change the sprite once per frame (The screen updates 60 times per second) any more is wasted processing power.
If you want an example of managing many objects at once the Space Race program I wrote covers sprites animating many sprites once per 60, 30, and 15 frames per second with sound all at the same time.