【发布时间】:2015-04-13 17:21:23
【问题描述】:
我正在尝试创建一个我要在其上绘制文本按钮的舞台。
我可以正常启动程序而没有任何错误。但是没有出现文本按钮。
问题可能是我无法设置我正在使用的舞台的大小。
下面是初始化代码:
@覆盖 公共无效调整大小(int宽度,int高度) { 如果(阶段 == 空) 阶段 = 新阶段();
stage.clear();
Gdx.input.setInputProcessor(stage);
TextButtonStyle style = new TextButtonStyle();
style.up = skin.getDrawable("Button");
style.down = skin.getDrawable("Button");
style.font = buttonFont;
startGameBtn = new TextButton("Start Game", style);
startGameBtn.setWidth(300);
startGameBtn.setHeight(150);
startGameBtn.setX(Gdx.graphics.getWidth() / 2 - startGameBtn.getWidth() / 2);
startGameBtn.setY((float) (Gdx.graphics.getHeight() / 1.5));
startGameBtn.addListener(new InputListener()
{
});
stage.addActor(startGameBtn);
}
这里是我画按钮的地方:
public void render(float delta)
{
Gdx.gl20.glClearColor(0, 0, 0, 1);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
sb.begin();
stage.draw();
sb.end();
}
感谢您的帮助! :)
【问题讨论】:
-
调整大小?你不是说创造吗? (我已经有一段时间没有使用 libgdx 了,我现在没有条件进行测试)
-
不,我的意思是调整大小,所以每当你调整窗口大小时它都会缩放。
-
是的,刚刚注意到在生命周期开始时也会调用 resize :)
-
是的。但是你知道如何解决这个问题吗?不画任何东西..
-
天哪。我觉得自己好傻。它实际上一直在绘制,我只有一个黑色按钮和一个黑色背景。 RIP