抱歉,我无法清楚地描述我的问题。我重新描述一下:
它只有一个游戏视图,该视图由GameScreen类实现,而GameScreen类是libgdx中Screen的子类:
public class LaohuGame extends Game {
public static final int FRUIT_NUM = 24;
public static final String WORK_DIR = "Desktop/assets/";
@Override
public void create() {
GameScreen gameScreen = new GameScreen(this);
setScreen(gameScreen);
}
public class GameScreen extends LaohuScreen {
private final Stage stage;
public static int START_X = 11;
public static int START_Y = 199;
public GameScreen(Game game) {
super(game);
stage = new Stage(GAME_WIDTH,GAME_HEIGHT,true);
//add actors to the stage
}
public class LaohuScreen implements Screen{
int GAME_WIDTH;
int GAME_HEIGHT;
protected Game game;
public LaohuScreen(Game game) {
this.game = game;
GAME_WIDTH = Gdx.graphics.getWidth();
GAME_HEIGHT = Gdx.graphics.getHeight();
}
GAME_WIDTH,GAME_HEIGHT等于手机屏幕的宽度,高度,因此游戏视图会覆盖整个手机屏幕。
Screen
libgdx中的子类实现。我认为完成的游戏应如下图所示:A button bar is added to the bottom of the phone screen. When I click one of the 4 buttons, the game view switched, but the button bar didn't switch. For example, if player clicks the "Rank" button, game set the view to Rank View(implemented by Rank screen) which shows players' scores, and the buttons still visible:
I can think of 2 ways to keep the button bar visible:
Combine button bar and game view into a libgdx's Screen. I think it is a waste because I need to draw 4 buttons in every screen, totally 16 buttons in 4 Screens.
Split phone screen into 2 areas; game view area and button bar area. Game view area implemented by libgdx's Screen and I can switch game view by setScreen method. The problem is that libgdx's Screen seems always fills the whole phone screen; I can't set the screen's width and height. I tried using resize(int width, int height)
method to cut down the height of screen to leave a blank space for button bar, but it doesn't work.
Code:
public class LaohuGame extends Game {
public static final int FRUIT_NUM = 24;
public static final String WORK_DIR = "Desktop/assets/";
@Override
public void create() {
GameScreen gameScreen = new GameScreen(this);
setScreen(gameScreen);
}
@Override
public void setScreen(Screen screen) {
super.setScreen(screen);
this.getScreen().resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() * 5 / 10);
}
@Override
public void resize(int width, int height) {
if (getScreen() != null) getScreen().resize(width, height * 5 / 10);
}
}
Any suggestions are appreciated.
All libgdx things assume that the width and height always are equal to the "window" size. On a desktop machine this might be less than the whole screensize, but it will still fill the whole render area. On a phone it will most likely always be the phones display size.
将其设置为较小的值将无济于事,因为它不会仅使用渲染区域的一部分。相反,您会得到奇怪的拉伸结果。
不要更改从resize方法获得的值。取而代之的是使用第一个解决方案,并在游戏屏幕底部渲染按钮。
您无需在此处重复任何代码。实现类似“ ButtonBarGUI”的东西,该东西使用Stage和scene2d.ui东西在屏幕底部呈现四个按钮,然后通过Stage.draw()重复使用此帮助器类在任何屏幕上呈现按钮栏。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句