简体   繁体   中英

Opening 2 dialogs in Scene2D-dialog LibGdx

I'm using Scene2d dialog in my game to create pop-ups. They are supposed to be questions and the player has to answer them. After the player has answered the question it's supposed to create another pop-up to give feedback. The answering part is working correctly as is identifying the correct answer. However I can't create the feedback button correctly. Currently the player gets asked a question. Then he answers and nothing. When he gets asked another question the feedback pops up on top of the next question. TLDR: Question -> answer -> feedback in one loop is what I'm looking for. Here's the code for the part that is not working properly:

do{
    if(DialogOma.wasClicked) {
        if (DialogOma.wasTheAnswerCorrect) {
            int ID = friendlyNPCs.get(j).getID();
                if(GameScreen.isEnglish) {
                    diaTest = new DialogOma("Questionjabs", disTestSkin, 1, myBundleEn, ID, "resultoikein", "ok");
                                         }
                else{
                    diaTest = new DialogOma("Vastausmies", disTestSkin, 1, myBundleFi, ID, "resultoikein", "ok");
                    }
                    diaTest.getSkin().getFont("default-font").getData().setScale(3f, 3f);
                    diaTest.show(stage);
                    DialogOma.wasTheAnswerCorrect = false;
                    Player.rightAnswer = true;
                    DialogOma.wasClicked = false;
                    Player.hasAnswered = true;
                                            }
                    else if (!DialogOma.wasTheAnswerCorrect) {
                        int ID = friendlyNPCs.get(j).getID();
                            if(GameScreen.isEnglish){
                                diaTest = new DialogOma("Vastausmies", disTestSkin, 1, myBundleEn, ID, "resultvaarin", "ok");
                                                    }
                            else{
                                diaTest = new DialogOma("Vastausmies", disTestSkin, 1, myBundleFi, ID, "resultvaarin", "ok");
                                }
                     diaTest.getSkin().getFont("default-font").getData().setScale(3f, 3f);
                     diaTest.show(stage);
                     DialogOma.wasTheAnswerCorrect = false;
                     Player.rightAnswer = false;
                     DialogOma.wasClicked = false;
                     Player.hasAnswered=true;
                        }
                    }
                }while(!Player.hasAnswered&&!diaTest.isVisible());

Most of the code is just to check the language pack to be used. DialogOma.wasTheCorrectAnswer is used to determine which pop-up screen should be used after answering Player.rightAnswer is used to handle the answer outside of dialog Player.hasAnswered and DialogOma.wasClicked are there from my testings. Haven't found aything by Googling it yet. Would really appreciate help here guys :)

EDIT: Here's what happens in the result method of dialog:

        if(object.equals("correct")) {
        ChangeScreens.gameIsOn = true;
        wasTheAnswerCorrect = true;
        wasClicked = true;
    }
    else{
        ChangeScreens.gameIsOn = true;
        wasTheAnswerCorrect = false;
        wasClicked = true;
    }
}

Okay, I managed to solve this by myself after sleeping over it. I had to make the first piece of code run as its own method which is controlled by the variable "wasClicked". Previously my buttons could be assigned with values "right" or "wrong" but I had to make it accept also value "ok" in order to get out of the loop. Probably not the best possible way to handle this but at least it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM