I have problem with resuming my game after pause
. I'm using SurfaceView
, and here is the most important part of code:
void pause() {
if (!pause) {
gameLoopThread.setRunning(false);
pause = !pause;
System.out.println("pause");
}
else {
gameLoopThread.setRunning(true);
System.out.println("end pause");
pause = !pause;
}
}
public GameView(Context context) {
super(context);
gameLoopThread = new GameLoopThread(this);
getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
gameLoopThread.setRunning(false);
while (retry) {
try {
gameLoopThread.join();
retry = false;
} catch (InterruptedException e) {}
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
//createSprites();
gameLoopThread.setRunning(true);
gameLoopThread.start();
thread1.start();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height)
{
}
When I use pause
first time, game is stopping, but when I'm trying to resume game by using pause
second time it doesn't work, but I have "end pause" printed in log.