我目前正在使用LibGDX创建一个游戏,现在我正在创建我的标题屏幕。如果将TextButton的宽度设置为舞台的宽度,但是在该按钮的左侧至右侧单击的任何位置都允许按下按钮而不是如果按下按钮,则我可以使它们居中,如果将TextButton放置在屏幕上时很麻烦你只需点击按钮本身。居中文本按钮到屏幕libgdx
如何让TextButton以游戏画面为中心并以对方为中心?我有三个TextButtons(新游戏,继续和退出游戏)。
任何帮助将不胜感激,谢谢!
编辑:
这是我的三个按钮的代码。
btnNG = new TextButton("New Game", btnStyle[0]) {
{
setName("New Game");
addListener(new InputListener() {
public boolean touchDown(InputEvent e, float x, float y, int pointer, int button) {
g.debugOut(btnNG.getName(), "touchDown?");
return true;
}
public void touchUp(InputEvent e, float x, float y, int pointer, int button) {
g.debugOut(btnNG.getName(), "touchUp?");
//g.switchScreen(new Mainscreen(g));
}
});
setWidth(sTitle.getWidth());
setPosition(0, (getHeight() * 2.5f));
}
};
btnContinue = new TextButton("Continue", btnStyle[0]) {
{
setName("Continue");
addListener(new InputListener() {
public boolean touchDown(InputEvent e, float x, float y, int pointer, int button) {
g.debugOut(btnContinue.getName(), "touchDown?");
return true;
}
public void touchUp(InputEvent e, float x, float y, int pointer, int button) {
g.debugOut(btnContinue.getName(), "touchUp?");
}
});
setWidth(sTitle.getWidth());
setPosition(0, (getHeight() * 1.4f));
}
};
btnExit = new TextButton("Exit Game", btnStyle[0]) {
{
setName("Exit Game");
addListener(new InputListener() {
public boolean touchDown(InputEvent e, float x, float y, int pointer, int button) {
g.debugOut(btnExit.getName(), "touchDown?");
return true;
}
public void touchUp(InputEvent e, float x, float y, int pointer, int button) {
g.debugOut(btnExit.getName(), "touchUp?");
//Gdx.app.exit();
}
});
setWidth(sTitle.getWidth());
setPosition(0, (getHeight() * .3f));
}
};
这是我迄今为止,它是中心,但这样做使得它能够在任何地方通过按压屏幕的实际文本的左/右上点击。
请包括一些正在创建按钮并将纹理附加到它。 –
我用一些代码更新了我的帖子。 –