Android 游戏中主游戏循环放置在哪里
我正在尝试使用 OpenGL 为 Android 上的游戏编写一些框架。我想知道,我应该将主游戏循环代码放在哪里?
到目前为止,我最好的候选方法是 Renderer.onDrawFrame(...) 方法,它似乎是按帧调用的,因此代码如下所示:
void onDrawFrame(GL10 gl)
{
preLoopActions();
m_gameScene->onUpdate();
m_gameScene->onRender(gl);
postLoopActions();
}
有没有更好的方法?我不喜欢这个,因为1)我必须在android希望我渲染的地方混合更新和渲染,2)这个方法似乎是从一个单独的“渲染线程”调用的,这增加了游戏的复杂性。
I am trying to write some skeleton for a game on android, using OpenGL. I would like to know, where should I place my main game loop code?
So far, my best candidate is Renderer.onDrawFrame(...) method, which seems to be called per-frame, so the code looks like this:
void onDrawFrame(GL10 gl)
{
preLoopActions();
m_gameScene->onUpdate();
m_gameScene->onRender(gl);
postLoopActions();
}
Is there any better approach? I dislike this one because 1) I have to mix updating and rendering in the place, where android expects me just to render, and 2) this method seems to be called from a separate "rendering thread", which increases game complexity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将数学和绘图逻辑分开。您想要的是创建一个线程,该线程在该循环中具有一个运行循环,您运行 math() 部分,然后在工作时调用 render() 部分,有一些技术可以控制循环的计时。
Separate the math and drawing logic. What you want is to create a thread that has a run loop in that loop you run the math() part and then call the render() part when you have that working there are some techniques to control the timing of the loop.
您是否考虑过使用像 AndEngine 这样的框架。它有一个叫做 GameActivity 的东西,它让生活变得非常简单。这些例子很容易上手。
Have you considered working with framework like AndEngine. It has something called as a GameActivity which makes life quite easy. The examples quite easy to pick up on.