Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 10, 2009, 12:47 PM   #1
PizzaTray
macrumors newbie
 
Join Date: Oct 2009
How to run code just once every time i want in game loop?

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. */

}

Last edited by PizzaTray; Nov 10, 2009 at 01:19 PM.
PizzaTray is offline   0 Reply With Quote
Old Nov 10, 2009, 03:08 PM   #2
xsmasher
macrumors regular
 
Join Date: Jul 2008
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?
xsmasher is offline   0 Reply With Quote
Old Nov 10, 2009, 03:35 PM   #3
PizzaTray
Thread Starter
macrumors newbie
 
Join Date: Oct 2009
Quote:
Originally Posted by xsmasher View Post
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?
Thank u, it works great
PizzaTray is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Creating the iOS game Run Crab Run SambaPanda iPhone and iPod touch Apps 2 Jul 14, 2013 11:42 PM
How to code & run PHP on Mac OS X (10.6)? mnya Mac Applications and Mac App Store 4 Jun 26, 2013 06:02 PM
Compiling C Code To Run In Mobile Terminal Marjamrob1 Mac Programming 8 Jan 29, 2013 04:20 PM
[Game] Run Tappy Run (by Tapps) - Universal App fwatanabe iPhone and iPod touch Apps 0 Jul 16, 2012 04:22 PM
[Game] Run Tappy Run for iOS fwatanabe iPhone and iPod touch Apps 1 Jul 12, 2012 05:33 AM

Forum Jump

All times are GMT -5. The time now is 07:50 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC