lundi 2 janvier 2017

Java : Simple Variable Issue

My code seems to me clean I don't understand why it won't work.

There is a button, it's supposed to change the sprite drawn when you click on it (this step works) and when you click on it it's also supposed to add +1 to my variable planetCount, the purpose of this step is to get the planet sprite drawn :

right.addListener(new ClickListener() {
            public void clicked(InputEvent event, float x, float y) {

                sound.play(0.2f);

                if (planetCount <= 4) {
                    choixRegion.setRegion(choix2Region);
                    choix2Region.setRegion(choix3Region);
                    choix3Region.setRegion(choix4Region);
                    choix4Region.setRegion(choix5Region);
                    choix5Region.setRegion(choixRegion);

                }
                else if(planetCount < 4){
                    planetCount = planetCount + 1;
                }
                else if(planetCount > 4){
                    planetCount = 4;
                }


            }


        });

and the problem is there, for all the planet choices it gives returns me the same screen (StartGame) to sum up if I have planetCount = 1 , it should returns me Itryon's Screen but regardless of the planetCount value it always returns StartGame screen:

oui.addListener(new ClickListener() {
                    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
                    {

                        if(planetCount == 0){
                            game.setScreen(new StartGame(game));
                        }
                        else if(planetCount == 1){
                            game.setScreen(new Itryon(game));
                        }
                        else if (planetCount == 2){
                            game.setScreen(new Nernel(game));
                        }
                        else if(planetCount == 3){
                            game.setScreen(new Abela(game));
                        }
                        else if(planetCount == 4){
                            game.setScreen(new StartGame(game));
                        }


                        sound.play(0.2f);
                        music.stop();
                        return true;
                    }

So where is my mistake ?

Aucun commentaire:

Enregistrer un commentaire