PDA

View Full Version : How to run code just once every time i want in game loop?




PizzaTray
Nov 10, 2009, 11:47 AM
I'm working on a game to the iphone with opengl es, and every time i have some other problem caused by the situation- that i can't run just one-time code in the game loop.

what should i do :( ?

EDIT:

I'll try to explain my problem here more deeply -

Example:
//
-init...
-game loop {

delta,
update,
render,

/* in the game loop ,as example, i want to run some method just one time, when, let's say, has a collision of explosion, Run the explosion-animation just once. */

}



xsmasher
Nov 10, 2009, 02:08 PM
Use an "if" statement to check for your condition, then inside the "if" so something that will prevent the "if" from being triggered the next time around. Something like this (pseudocode):


if ((ship touching laser) && !ship.dead{
//trigger animation here
[myAnimation trigger];

//prevent this if from being triggered next time
ship.dead=true;
}


Alternately, you could remove the laser inside the if, so that the laser doesn't exist to trigger the collision next time.

Makes sense?

PizzaTray
Nov 10, 2009, 02:35 PM
Use an "if" statement to check for your condition, then inside the "if" so something that will prevent the "if" from being triggered the next time around. Something like this (pseudocode):


if ((ship touching laser) && !ship.dead{
//trigger animation here
[myAnimation trigger];

//prevent this if from being triggered next time
ship.dead=true;
}


Alternately, you could remove the laser inside the if, so that the laser doesn't exist to trigger the collision next time.

Makes sense?

Thank u, it works great :)