将暂停屏幕绘制为播放屏幕上的图层-LibGdx [英] Drawing pause Screen as a layer over the play screen-LibGdx

查看:17
本文介绍了将暂停屏幕绘制为播放屏幕上的图层-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.

就像下面的游戏截图:

我只能在我的游戏中使用单独的背景和所有内容制作一个新的暂停屏幕.我想按原样显示暂停的游戏.在此之上,我可以为恢复按钮、框等绘制图形,就像屏幕截图一样.

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?

推荐答案

在 Gamescreen 内部,您正在使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆