Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 10, 2009, 11:47 AM   #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 12:19 PM.
PizzaTray is offline   0 Reply With Quote
Old Nov 10, 2009, 02: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, 02: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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Tutorial: How to get PCSX2 to run on Mac (without BootCamp) Mirrors Mac Applications and Mac App Store 22 Jun 14, 2013 08:19 PM
Slide To Run - (by 42Games) - FREE!! - Universal App Lakoo iPhone and iPod touch Apps 1 Aug 3, 2011 05:55 AM
[HOW TO] DIY iPhone 4 Swivel Car Mount QuarterSwede iPhone Accessories 13 Mar 8, 2011 02:51 PM
How to stop iPhoto popping up every time I put in SD card? danetello MacBook Pro 3 Feb 10, 2011 06:30 PM
How to run softwares made for System 7.5.2 in Leopard? hajime OS X 1 Apr 6, 2008 08:54 AM


All times are GMT -5. The time now is 04:37 AM.

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

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