Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

How can I switch between Stages in Libgdx?

$
0
0

Hello I used Stage for my menu, because this way I could add my whole UI to a CompositeActor and get the buttons, as was suggested to my in Overlap2Ds forum.
Getting the button and etc works right except the code for starting new PlayStage doesn’t work. When I click the button Play, the screen becomes black but the PlayStage doesn’t load. Here is my code, hope someone can help.

public class MenuStage extends Stage {

private SceneLoader sc;
private ButtonClickListener buttonClickListener;
private CompositeActor UI;
private CompositeItemVO compositeItemVO;
private PlayStage playStage;
private Stage thisStage;


public MenuStage() {
    initMenu();
}


private void initMenu() {
    Gdx.input.setInputProcessor(this);
    buttonClickListener = new ButtonClickListener();
    sc = new SceneLoader();
    thisStage = this;
    compositeItemVO = new CompositeItemVO(sc.loadScene("MainMenu").composite);
    UI = new CompositeActor(compositeItemVO, sc.getRm());
    UI.getItem("playbutton").addListener(buttonClickListener);
    UI.getItem("playbutton").addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            playStage = new PlayStage();
            playStage.act();
            playStage.draw();
            thisStage.dispose();


        }
    });
    addActor(UI);

    }  
 }

Viewing all articles
Browse latest Browse all 434

Trending Articles