Drawing pause Screen as a layer over the play screen-LibGdx

前端 未结 2 1147
耶瑟儿~
耶瑟儿~ 2021-01-26 08:02

In my LibGdx Game I created pause functionality.While playing game,If I press pause button,a separate screen with resume button displays.

What actually I want to do is t

2条回答
  •  别那么骄傲
    2021-01-26 08:14

    Inside Gamescreen, you're using stage for UI(buttons to navigate). I am pretty sure you're doing like this.

    private uiStage;
    private boolean isPause;
    private Group pauseGroup; 
    
    public void render(){
    
        if(!isPause) UpdateGame();    
        DrawGame();         
    
        uiStage.act();
        uiStage.draw();
    }
    

    Create a Group whenever you want to pause your game and remove that group when you want to resume your game. You can also crate your Group once and add all pause UI in show() method. Add that group to stage when you want to show pause and remove when you resume your game.

    public void pauseGame(){
    
       isPause = true;
       pauseGroup = new Group;
       Image semiTransparentBG= ......
       // setSize(Size of screen) and make it semi transparent.
       pauseGroup.addActor(semiTransparentBG);
    
       //crate all other pause UI buttons with listener and add to pauseGroup
    
       stage.addActor(pauseGroup);
    
    }
    
    public void resumeGame(){
    
        if(isPause){
          isPause=false;
          pauseGroup.remove();
        }  
    }
    

提交回复
热议问题