Thanks for the fast reply. But I don't fully understand it, because the UI thread creates, for example, the surfaceview. And from the game thread I update yje surfaceview. But if the UI thread is paused, so is also the surfaceview...
At the moment I have the following:
1. The activity startGame is started. startGame calls the surfaceview gameView. startGame als starts the thread gameThread.
2. Game thread starts a loop, and in every loop all the calculations are done and the following is done:
- Code: Select all
while(_run) {
try {
c = _surfaceHolder.lockCanvas(null);
synchronized(_surfaceHolder) {
mgameView.onDraw(c);
runGameCode(c);
}
} finally {
if(c != null){
_surfaceHolder.unlockCanvasAndPost(c);
}
}
}
mgameView.onDraw(c); calls the onDraw function in the gameView which clears the background and draws it again. runGameCode(c) executes all the calcultaions in the gameThread.
Inside the startGame activity I have the onTouchEvent which at the end: Thread.sleep(16);
But the higher I put the number, there is still quite a big framedrop if I move my finger. Even when I take no history.
So how should the structure of the game than be?