我正在尝试构建如下图所示的布局:
我应该使用两个阶段吗?两个摄像头?一个带 splitPane 的阶段? 我希望顶部屏幕是整个设备高度的一半。顶部屏幕将有动画 Actor 和单个背景图像,以及靠近屏幕顶部的一些标签。
下方屏幕应该是一个带有信息的滚动 Pane ,底部是菜单和后退按钮。
如果屏幕调整大小,我如何确保它们之间的比例?
编辑 2014-03-28:
嗨!
我尝试按照建议使用两个阶段,我很高兴。以为我分享了我的第一次尝试。结果是这段代码:
package se.appltini.mygdxtest;
//imports omitted
public class DualStageTutorial extends ScreenAdapter {
private Stage upperStage;
private Stage bottomStage;
private Skin skin,menuSkin;
@Override
public void show() {
upperStage = new Stage();
bottomStage = new Stage();
skin = new Skin(Gdx.files.internal("uiskin/uiskin.json"));
menuSkin = new Skin(Gdx.files.internal("menuSkin/uiSkin.json"),new TextureAtlas(Gdx.files.internal("menuSkin/uiskin.atlas")));
Image upperImage = new Image(menuSkin.getPatch("menuTexture"));
upperImage.setFillParent(true);
upperStage.addActor(upperImage);
Image bottomImage = new Image(menuSkin.getPatch("menuTexture"));
bottomImage.setFillParent(true);
//setting alpha to 0.5f so we can see the different stages
bottomImage.setColor(1f, 1f, 1f, 0.5f);
bottomStage.addActor(bottomImage);
}
@Override
public void resize(int width, int height) {
}
@Override
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
upperStage.act(delta);
bottomStage.act(delta);
/*Upper Half*/
//set the openGl viewport to half the screenheight and starting y from the middle of the screen
Gdx.gl.glViewport(0,Gdx.graphics.getHeight()/2,Gdx.graphics.getWidth(),Gdx.graphics.getHeight()/2);
upperStage.draw();
/*bottom Half*/
//set the openGl viewport to half the screenheight and starting y from the bottom of the screen
Gdx.gl.glViewport(0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight()/2);
bottomStage.draw();
}
@Override
public void hide() {
dispose();
}
@Override
public void dispose() {
upperStage.dispose();
bottomStage.dispose();
skin.dispose();
menuSkin.dispose();
}
最佳答案
此处的最佳做法是使用两个不同的阶段。
使用两个阶段将简化设计,因为 2d 动画的视口(viewport)管理将大大简化。事件处理也必须是完全不同的风格。与 2d 动画相比,您的信息面板在 Actor 中不会有太多相对布局变化。
只有当两个内容以某种形式相互重叠时,使用同一个阶段才有意义。我敢肯定这里不是这种情况。您的信息面板将始终显示在动画上方(很可能)。
希望这对您有所帮助。
关于java - 如何在 libgdx 中构建分屏?一个用于二维动画,一个用于信息面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22422424/