我目前正在使用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));
}
};
這是我迄今爲止,它是中心,但這樣做使得它能夠在任何地方通過按壓屏幕的實際文本的左/右上點擊。
請包括一些正在創建按鈕並將紋理附加到它。 –
我用一些代碼更新了我的帖子。 –