Andengine onScreen Pause Button

I want to create a pause on-screen button in andengine

Now I add a sprite, and when I touch it, I do engine.stop (), the problem with this is that the engine does not process more touches until I resume the game (now I use the menu button for this), so there is way to achieve it?

Thank!

+3
source share
6 answers

I found that the best way to do this is to create a scene, and when it is paused, set the onManagedUpdate override this way

@Override
onManagedUpdate(float pSecondsElapsed){
 if(mPaused) super.onManagedUpdate(0);
 else        super.onManagedUpdate(pSecondsElapsed);
}

This way everything works fine, and you can do it at the game level and update the menu layer as usual,

+4
source

AndEngine, , AndEngine, , . !

+4

. , , , MenuScene . .setPosition() MenuItem, .buildAnimations() PauseMenu.

, , . .

: https://github.com/reittes/On-Screen-Pause-Button

GoodLuck

+2

What I would do is add a “paused” logical file in your file, and then set it to true, and then turn on updating your module with a block if (!pause) {...}to stop it when paused. Not the most elegant solution, but it worked in my game and did not cause performance problems without pauses.

+1
source

Psedu Code

@Override
public boolean onKeyDown(final int pKeyCode, final KeyEvent pEvent) {
    if (pKeyCode == KeyEvent.KEYCODE_MENU && pEvent.getAction() == KeyEvent.ACTION_DOWN) {
        if (this.mEngine.isRunning()) {
            gSceneGlobal.setChildScene(this.mGamePauseScene, false, true, true);
            this.mEngine.stop();
        } else {
            gSceneGlobal.clearChildScene();
            this.mEngine.start();
        }
        return true;
    } else {
        return super.onKeyDown(pKeyCode, pEvent);
    }
}
+1
source

I create my class (MyEngine extends Engine) and changed

@Override
public boolean onTouch(final View pView, final MotionEvent pSurfaceMotionEvent) {                      
if(!isRunning()) {
  // add your code for engine.stop();
  }
}

and create the MyEngine engine in the game class;

+1
source

All Articles