I have a problem creating a gameloop for my first game. I read a lot about this, but still can not understand. It is based on OpenGL, so I used onDrawFrame as a game loop, and it works fine on my phone. The problem is that onDrawFrame is the update time, it depends on the hardware, so it works too fast on some devices. Therefore, I want to add a separate game cycle, which will be updated with a constant period of time on all smartphones. (and onDrawFrame will only care about the graphics, as it should be)
At the moment I have:
- class myGameRenderer with all openGl files onDrawFrame
- myGLSurfaceView supporting touch events
- myGameActivity
onDrawFrame activates the function myGameUpdate, which controls the position change of all objects in the game depending on the information from myGLSurfaceView
I tried to create a new Runnable, but it does not seem to work, I canβt figure out how to run this runnable and where I should place it (I tried to put it in the myGameRenderer class, but it didnβt work, nothing moved:
private final Runnable mUpdateDisplay = new Runnable() { @Override public void run() { update(); }}; private void update() {
but I think I have no idea - I mean that I create this runnable. I tried putting it in onCreateSurface to run it, but no effect. So is this a general idea? And how to start a cycle? Where to place it? Or should I use any other way?
source share