Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit)

Level Selection Screen : Using the buttons !

Well, that's cool this level selection screen, but what is even better is that we can use it ! You know, press a button a play the wanted level !

For that, in the LevelSelectionScreen.java, we need this code in the show() :

public void show() {
    Gdx.input.setInputProcessor(stage);
        
    for(int i = 0; i < levels.size; i++){
        if(levels.get(i).getStyle() == textButtonStyle)
            buttonAction.levelListener(game, levels.get(i), (i+1));
    }
        
    backButton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y){
           game.setScreen(new MainMenuScreen(game));     
        }
    });
}

You can see there is a for loop that calls a mysterious "buttonAction.levelListener(game, levels.get(i), (i+1));"

The ButtonAction.java is just an helper class to attribute the right action to the right button, it is to say, call the right level, when you press a button. Its levelListener() function is :

public void levelListener(final MyGdxGame game, TextButton bouton, final int niveau){
    bouton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y){
            GameConstants.SELECTED_LEVEL = niveau;
             try{
                 game.setScreen(new GameScreen(game));
             }
                catch(Exception e){
                System.out.println("The level doesn't exist !");
            }
        }
    });
}

And that's it ! You have a fully operational level selection screen !

Now, let's work on the sounds !

I started yesterday, and I can say it's extremely painful !