小编use*_*848的帖子

如何在不使用NSTimer的情况下在iPhone上进行游戏循环

为了将我的游戏干净地移植到iPhone,我正在尝试制作一个不使用NSTimer的游戏循环.

我在一些示例代码中注意到,如果使用NSTimer,您可以在开头设置类似的代码

    self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

其中drawView看起来像:


- (void)drawView 
{
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    mFooModel->render();
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
Run Code Online (Sandbox Code Playgroud)

当使用这种技术时,mFooModel渲染得很好,但我反而想让我自己的游戏循环调用drawView而不是让NSTimer调用drawView 60次.我想要像:


while(gGameState != kShutDown)
{
    [self drawView]
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我这样做时,我得到的只是一个黑屏.为什么会这样?无论如何我可以实现我在这里描述的内容吗?

我想避免NSTimer的原因是因为我想在游戏循环中进行物理和AI更新.我使用自己的时钟/计时器来跟踪已经过的时间,以便我可以准确地完成这项工作.渲染尽可能快.我尝试使用本文中描述的一些技术

这有点像一个冲动的问题(你在整天编码,卡住之后所做的那个问题,希望早上的答案就在那里)

干杯伙计们.

iphone loops opengl-es

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

iphone ×1

loops ×1

opengl-es ×1