Thanks for the video; now I understand the "jerk" part.
The explanation for that is simple: your code is doing this (simplified):
while (running) {
canvas = this.surfaceHolder.lockCanvas();
this.gameLogic.update();
this.gameLogic.render(canvas);
surfaceHolder.unlockCanvasAndPost(canvas);
}
public void render(Canvas canvas) {
if (!gameOver) {
...draw...
}
}
If gameOver
is true, your render()
function doesn't draw anything, so you get the previous contents of the buffer.
You might expect this to show whatever was drawn from the frame just before this one. However, the SurfaceView surface is double- or triple-buffered. So if you just keep calling lock/post without drawing anything, you'll cycle through the last two or three frames.
Simple rule: if you lock the surface, you need to draw. If you don't want to draw when the game is over, you need to put your "game over" test back before you lock the canvas.