Yesterday, when I design my game in AndEngine, I found I cannot create an onscreen pause button in my game! So frustrate!
I try to create a ButtonSprite as the pause button of my game! When the pause button click, I take mEngine.stop(). But when I click the pause button agagin, it cannot star...(Of course, I wrote a bool variable in order to control mEngine.start() or mEngine.stop()).
So, I read the source code of AndEngine, I found in mEngine.stop(), mRunning become false. In Engine.onTickUpdate(), if mRunning is false, it will not update, but in it's update, it will listen the touch event of the screen!
In AndEngineExamples, there is an example of pause, but it used Menu key instead of an onscreen button. It works, because Menu key is system listen, not engine listen....
So, I have a try to Engine.java. I add a bool variable called pause inited false. When I click the pause button on screen, the pause turn true, and I will judge the pause in Engine.update(), as follow,
Using java Syntax Highlighting
- public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException
- {
- final float pSecondsElapsed = pNanosecondsElapsed * TimeConstants.SECONDS_PER_NANOSECOND;
- this.mSecondsElapsedTotal += pSecondsElapsed;
- this.mLastTick += pNanosecondsElapsed;
- this.mTouchController.onUpdate(pSecondsElapsed);
- if (!pause)
- {
- this.onUpdateUpdateHandlers(pSecondsElapsed);
- this.onUpdateScene(pSecondsElapsed);
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
It means whatever the pause is true or false, it will listen the touch on screen!
