Question

I'm working on a game application which needs an end-game dialog. I tried to do it a several ways, but couldn't reach to work.

My game algorithm's method runs on a separate thread. After finishing the gameplay, in that thread i've tried to call (in the GameScene's class) like getChildren().add(endDialog), but nothing happened. If I added it in it's constructor and than in the gameplay-thread's end put getChildren.get(0).toFront(), still nothing happened.

Any suggestion?

EDIT

Found a way that work, but it's not that perfect:

   setOnMouseMoved(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            if(ended) {
                getChildren().add(new EndDialog());
                getChildren().get(25).setOpacity(0.7);
            }
        }
    });

Its only problem is that after I've finished playing, I have to move my mouse one more time in order the dialog to appear.

How should I catch in time the ended field's value?

Was it helpful?

Solution

What kind of thread did you use ?

in JavaFX you have to Use the Service classe to do the things correctly and don't make freez the GUI stuff.

On this service you have an onSucceeded field, so if you listen it you can do what you want when it have finished to work.

You can laso take a look a this

And if you want nice dialogs take a look at ControlFX

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top