为了将我的游戏干净地移植到 iPhone,我正在尝试制作一个不使用 NSTimer 的游戏循环。
我在一些示例代码中注意到,如果使用 NSTimer,您需要在开始时使用类似的内容进行设置
self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
其中drawView看起来像这样:
- (void)drawView
{
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
mFooModel->render();
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
使用此技术时,mFooModel 渲染得很好,但我想制作自己的游戏循环来调用drawView,而不是让NSTimer 每秒调用drawView 60 次。我想要这样的东西:
while(gGameState != kShutDown)
{
[self drawView]
}
不幸的是,当我这样做时,我得到的只是黑屏。为什么会发生这种情况?无论如何,我可以实现我在这里描述的内容吗?
我想避免 NSTimer 的原因是因为我想在游戏循环中进行物理和 AI 更新。我使用自己的时钟/计时器来跟踪已经过去的时间,以便我可以准确地做到这一点。渲染尽可能快地发生。我尝试使用中描述的一些技术本文 http://dewitters.koonsolo.com/gameloop.html
这是一个有点冲动的问题(你在编码一整天后遇到的问题,被困住了,希望早上就能得到答案)
干杯,伙计们。