Android 游戏中主游戏循环放置在哪里

发布于 2024-09-28 06:56:22 字数 403 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十二 2024-10-05 06:56:22

将数学和绘图逻辑分开。您想要的是创建一个线程,该线程在该循环中具有一个运行循环,您运行 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.

一梦等七年七年为一梦 2024-10-05 06:56:22

您是否考虑过使用像 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文