开发者

Is there an Objective-C equivalent to XNA's update function?

开发者 https://www.devze.com 2023-04-03 08:51 出处:网络
What function can be used in Objective-C, for iPhone, that wo开发者_Python百科rks like the update function in the XNA framework?

What function can be used in Objective-C, for iPhone, that wo开发者_Python百科rks like the update function in the XNA framework?

Like this:

Is there an Objective-C equivalent to XNA's update function?

for automantic update.


You'll have to do the heavy lifting yourself, typically by using threading or an NSTimer object.

For example:

    [NSTimer scheduledTimerWithTimeInterval:0.033f target:self
            selector:@selector(mainLoop:) userInfo:nil repeats:NO];

where the "selector" points to your game loop function. Make sure the game loop creates another NSTimer after calling Update and Render:

    - (void) mainLoop: (id) sender
    {
        [Update];
        [Render];

        [NSTimer scheduledTimerWithTimeInterval:sleepPeriod target:self 
                selector:@selector(mainLoop:) userInfo:nil repeats:NO];
    }

Also check out this thread for threading discussion: What is a better way to create a game loop on the iPhone other than using NSTimer?

Or Google "iOS gameloop NSTimer".

0

精彩评论

暂无评论...
验证码 换一张
取 消