1

I'm greatly confused on this. What is don't understand is how the stage and table layouts exactly work. All i want are 3 buttons that sends me to another screen. Could someone please write out an example for me to work with? Here is the code I have so far.

public class Menu implements Screen {
private SlingshotSteve game;
private Stage stage;
private TextButton button;
private TextButtonStyle textButtonStyle;
private BitmapFont font;
{
stage = new Stage(new ExtendViewport(800, 840));
Gdx.input.setInputProcessor(stage);
Table table = new Table();
table.setFillParent(true);
table.center().center();
stage.addActor(table);
font = new BitmapFont();
textButtonStyle = new TextButtonStyle();
textButtonStyle.font = font;
button = new TextButton("This is a button!!!", textButtonStyle);
stage.addActor(button);
}
// View Port Camera
private Viewport viewport;
PerspectiveCamera camera;
public Menu(SlingshotSteve gam) {
 this.game = gam;
}
@Override
public void render(float delta) {
 Gdx.gl.glClearColor(0, 0, 0.2f, 1);
 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
 stage.act(Gdx.graphics.getDeltaTime());
 stage.draw();
 camera.update();
 game.batch.setProjectionMatrix(camera.combined);
 game.batch.begin();
 game.batch.end();
 if (Gdx.input.isTouched()) {
 game.setScreen((Screen) new GameScreen(game));
 dispose();
 }
}
@Override
public void resize(int width, int height) {
 // View Port Camera
 viewport.update(width, height); 
 stage.getViewport().update(width, height, true);
}
@Override
public void show() {
 // Viewport Camera
 camera = new PerspectiveCamera();
 viewport = new FitViewport(800, 480, camera);
}
@Override
public void dispose() {
 stage.dispose();
}
}
asked Sep 10, 2014 at 23:43

1 Answer 1

3

Don't add the button to the Stage. Instead add it to the Table you have created.

TextButton button1 = new TextButton("This is a button!!!", textButtonStyle);
TextButton button2 = new TextButton("This is a button!!!", textButtonStyle);
TextButton button3 = new TextButton("This is a button!!!", textButtonStyle);
table.add(button1);
table.row();
table.add(button2);
table.row();
table.add(button3);
table.row();
answered Sep 11, 2014 at 6:59
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.