Where to place main game loop in android game
Asked Answered
D

2

7

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.

Dionnedionysia answered 22/10, 2010 at 9:5 Comment(0)
M
2

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.

Metrify answered 3/11, 2010 at 19:10 Comment(0)
E
1

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.

Ethos answered 22/10, 2010 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.