How make a game loop on the iPhone without using NSTimer

前端 未结 5 1563
挽巷
挽巷 2021-01-31 23:53

In order to cleanly port my game to the iPhone, I\'m trying to make a game loop that doesn\'t use NSTimer.

I noticed in some sample code that, if using NSTimer, you\'d s

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 00:20

    Another option with iPhoneOS 3.1 is to use the new CADisplayLink api. This will call the selector you specify when the screen contents needs to be updated.

    displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(renderAndUpdate)];
    [displayLink setFrameInterval:2];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    

    The new OpenGL project template in XCode also use the CADisplayLink if you need some more example code.

提交回复
热议问题