绘图暂停屏幕作为播放屏幕上的一层

绘图暂停屏幕作为播放屏幕上的一层

本文介绍了绘图暂停屏幕作为播放屏幕上的一层-LibGdx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的LibGdx游戏中,我创建了暂停功能.在玩游戏时,如果我按暂停按钮,则会显示一个带有恢复按钮的单独屏幕.

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 that the pause screen should appear above the game play screen like a layer.

就像下面的游戏的屏幕截图一样:

Like the screen shot of a game below:

我只能用单独的bg和全部在游戏中制作一个新的暂停屏幕.我想按原样显示暂停的游戏.此外,我可以像截屏一样绘制用于恢复按钮,框等的图形.

I could only make a new pause screen in my game with separate bg and all.I want to display the paused game as it is.Above that I can draw graphics for resume button,box etc exactly like the screen shot.

如何像暂停屏幕的显示一样达到这一层?

How can I acheive this layer like display of pause screen?

推荐答案

在游戏屏幕内部,您正在使用界面UI(用于导航的按钮).我很确定您正在这样做.

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();
}

每当您要暂停游戏时都创建一个组,并在您要继续游戏时将其删除.您也可以创建一个组,然后在show()方法中添加所有暂停的UI.当您想显示暂停时将该组添加到舞台上,而在您继续游戏时将其删除.

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();
    }
}

这篇关于绘图暂停屏幕作为播放屏幕上的一层-LibGdx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:13