Reputation: 287
I am developing a game for Android using game engine. I want to have a pause and resume button on game screen.
I have implemented this by using MenuScene and for pausing the game I am using
engine.stop();
But once it stop the engine, it does not fire any touch or click events.
How to start the engine again?
or what can be the best way to implement the same ?
Upvotes: 4
Views: 2256
Reputation: 6018
I find that the easiest way to pause your game is doing the following:
mScene.setIgnoreUpdate(true);
mScene.setChildScene(mPauseScene, false, true, true);
when mScene
is your main game scene and mPauseScene
is the pause scene.
Then, to resume the game, you do:
mScene.clearChildScene();
mScene.setIgnoreUpdate(false);
Since the question mentioned a pause/resume button, I highly recommend this tutorial. It shows, in a very straight-forward way, how to implement such a button. I have used it in my game, and it works great.
Upvotes: 2
Reputation: 1156
To Pause the game:
GameScene.gameScene.setChildScene(pauseScreen, false, true, true);
add these lines to your game Screen.So that your game will go into pause
To Resume the Game:
GameScene.gameScene.clearChildScene();
Upvotes: 0
Reputation: 627
Okay,although i am not pro at andengine, i can give some advice. First of all, stopping the engine is not a pause solution that you are looking for. So instead of that,you must do it manuelly,which i mean;
Stop moving things:
To do this,you can use yourPhysicsWorld.unregisterPhysicsConnector()
function if you are using some physics.
Or you can just set velocity to zero of all moving things(setVelocity(0,0)
)
Stop Update System:
Simply you can do this with yourScene.unregisterUpdateHandler()
Save Important Data:
If you have some important data, you must save them first.I won't give detailed information about it but if you don't know how to store data,you can look for SQLite
and SharePreferences
on Google.
Remind that if you want to return to game,you have to register the Update Handlers and Physics Connectors back to the scene.
Upvotes: 4