开发者

Where to place main game loop in android game

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)开发者_StackOverflow中文版 
{
     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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜