Note that there are some explanatory texts on larger screens.

plurals
  1. POHow make a game loop on the iPhone without using NSTimer
    primarykey
    data
    text
    <p>In order to cleanly port my game to the iPhone, I'm trying to make a game loop that doesn't use NSTimer.</p> <p>I noticed in some sample code that, if using NSTimer, you'd set it up at the beginning with something like</p> <pre><code> self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES]; </code></pre> <p>where drawView would look something like:</p> <pre><code> - (void)drawView { glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); mFooModel->render(); glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); [context presentRenderbuffer:GL_RENDERBUFFER_OES]; } </code></pre> <p>When using this technique mFooModel renders fine, but I instead want to make my own game loop that calls drawView instead of having NSTimer call drawView 60 times a second. I would like something like:</p> <pre><code> while(gGameState != kShutDown) { [self drawView] } </code></pre> <p>Unfortunately when I do this, all I get is a black screen. Why does this happen? Is there anyway I can implement what I'm describing here?</p> <p>The reason I want to avoid NSTimer is because I want to do physics and AI updates in the game loop. I use my own clock/timer to keep track of the amount of time that has elapsed so that I can do this accurately. Rendering happens as fast as possible. I try to use some of the techniques as described in <a href="http://dewitters.koonsolo.com/gameloop.html" rel="noreferrer">this article</a></p> <p>This is somewhat of an impulsive question (the one you do after you've been coding all day, get stuck, and hope the answer is there by morning)</p> <p>Cheers guys.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload