How to run code just once every time i want in game loop?

Discussion in 'iPhone/iPad Programming' started by PizzaTray, Nov 10, 2009.

  1. macrumors newbie

    Joined:
    Oct 31, 2009
    #1
    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. */

    }
     
  2. macrumors regular

    xsmasher

    Joined:
    Jul 18, 2008
    #2
    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):

    Code:
    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?
     
  3. thread starter macrumors newbie

    Joined:
    Oct 31, 2009
    #3
    Thank u, it works great :)
     

Share This Page