I am currently creating a game using LibGDX and I am creating my Title Screen at the moment. I am having trouble centering TextButtons on the screen, I can get them centered fine if the set the width of the TextButton to the width of the stage but then anywhere you click left to right of that button allows the button to be pressed and not if you're just clicking on the button itself.
How could I get the TextButtons centered to the game screen and centered on each other? I've got three TextButtons(New Game, Continue and Exit Game).
Any help would be greatly appreciated, thanks!
Edit:
Here is the code for my three buttons.
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));
}
};
That is what I have so far, it is centered but doing so allows it to be clicked by pressing anywhere on the screen to the left/right of the actual text.