0
\$\begingroup\$

Pause dialog has to appear on top of the play screen, it has to appear on top of other objects.

I have tried to use

dialog.setZIndex(10); // or whatever number and I tried adding it in many places

It just doesn't work, how to make the dialog be on top of other objects? for a ccomplete version here

I'm using only one batch and the stage is used only to add background and dialog

  stage = new Stage();
  Gdx.input.setInputProcessor(stage);
  stage.addActor(bg); // somewhere else in the code
  stage.addActor(btnPause);
  camera.update();
  game.batch.setProjectionMatrix(camera.combined);
  stage.act(delta);
  stage.draw(); // and thats about it for stage
  game.batch.begin();
  font.setColor(Color.YELLOW);
  font.draw(game.batch, myScore + score, Gdx.graphics.getWidth(), camY);
  // and here I draw the game   game.batch.draw(game) and I'm using only one batch

I hope I didn't miss anything

If I put the game batch in state.RUN in an effort to hide objects when the pause dialogue appears, then when I resume, it will go to batch.end and exit the game

Pause

public void pause() {
 this.state = State.PAUSE;
 final Dialog dialogP = new Dialog("", skin, "pauseDialog") {};

 dialogP.setScale(4, 6);
 dialogP.setPosition(Align.center, Gdx.graphics.getHeight());


 dialogP.addAction(sequence(alpha(0),
  parallel(fadeIn(.5 f)),
  moveBy(0, -1000 f, .30 f, Interpolation.smooth),
  moveBy(0, 30 f, .40 f, Interpolation.smooth)));

 //PlayOn
 ImageButton btnPlayOn = UIFactory.createButton(txtrPlayOn);
 btnPlayOn.setSize(40, 40);
 btnPlayOn.setPosition(75, 75, Align.center);
 dialogP.addActor(btnPlayOn);

 //EndGame
 ImageButton btnEndGame = UIFactory.createButton(txtrEndGame);
 btnEndGame.setSize(40, 40);
 btnEndGame.setPosition(75, 55, Align.center);
 dialogP.addActor(btnEndGame);

 stage.addActor(dialogP);


 //playOnAction
 btnPlayOn.addListener(new ClickListener() {
  @Override
  public void clicked(InputEvent event, float x, float y) {
   dialogP.hide();
   resume();
  }
 });


 //EndGameAction
 //PlayButtonAcion
 btnEndGame.addListener(
  new InputListener() {
   @Override
   public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
    super.enter(event, x, y, pointer, fromActor);

    Actions.scaleTo(0.7 f, 0.7 f, 0.5 f, Interpolation.bounceOut);
    stage.addAction(Actions.sequence(Actions.moveBy(-stage.getWidth(), 0, .5 f), Actions.run(new Runnable() {
     @Override
     public void run() {
      game.setScreen(new MainMenuScreen(game));
     }
    })));

   }

  });


}

The basic principle is implemented from the accepted answer to this question

\$\endgroup\$
4
  • \$\begingroup\$ What does the draw method look like for the thing that renders the dialog? Are you using more than one Stage, are you using more than one Batch are you using the same Batch more than once in a single update? \$\endgroup\$
    – bornander
    Commented Mar 7, 2017 at 5:41
  • \$\begingroup\$ @bornander please read my edit \$\endgroup\$
    – Lynob
    Commented Mar 7, 2017 at 9:24
  • \$\begingroup\$ What does the code look like where you add the Dialog to the Stage? \$\endgroup\$
    – bornander
    Commented Mar 7, 2017 at 12:05
  • \$\begingroup\$ @bornander please read my edit \$\endgroup\$
    – Lynob
    Commented Mar 7, 2017 at 14:26

0

You must log in to answer this question.

Browse other questions tagged .