【发布时间】:2014-12-21 01:20:37
【问题描述】:
我目前正在使用 libgdx 为我的 Android 游戏创建一个对话框窗口。此对话窗口包含标签和按钮的集合,但还应包含图像。图像代表“剩余生命值指示器”,即带有指示玩家生命值符号的空指示器。该指标必须用代表剩余生命值的彩色矩形填充(见下面的屏幕截图)。
为了在 libgdx 的对话框上呈现它,我必须绘制一个图像和一个彩色矩形(红色矩形表示实际的剩余生命值)。我知道对话框支持图像的渲染,但我不知道如何先绘制矩形。
这是我到目前为止的代码:
public FuelFacilityDialog(GameWorld world, GuiComponent gui) {
super("Health check", gui.defaultSkin);
this.world = world;
this.gui = gui;
setModal(true);
setMovable(false);
setResizable(false);
Image healthIndicator = new Image();
Button button1 = new TextButton("heal", gui.defaultSkin);
Button button4 = new TextButton("Exit", gui.defaultSkin);
healthIndicator.setDrawable(new TextureRegionDrawable(AssetLoader.healthIndicatorV));
healthIndicator.setScaling(Scaling.fit);
setObject(button1, true);
setObject(button4, false);
Table imageTable = new Table();
Table buttonTable = new Table();
imageTable.add(healthIndicator).width(100).height(200);
buttonTable.add(button1).width(100).height(50).expandY();
this.getContentTable().padTop(20);
this.getContentTable().padBottom(20);
this.getContentTable().add(imageTable);
this.getContentTable().add(buttonTable).height(200);
getButtonTable().add(button2);
}
【问题讨论】:
-
您可以使用 ShapeRenderer 来绘制某种健康条。 libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/…
标签: java android user-interface libgdx