Question

Ok, so i have a problem with javafx, the netbeans 6.9.1 version that is (i know it's a bit old but i have to do this for a final assignement for school). So for the assignement i have to code a memory game (concentration). Now i want to program a delay so when i flip a card the function waits for like 1.5 seconds so that you can see the turned card. however, when i make a while loop to wait for the 1.5 second mark the program just freezes and the variable "time02" won't update. i then have to manually shut the program down via task manager because it just freezes. Here's a snippet of the code with the timeline and a small piece of the function. i also included the timeline for the clock which weirdly enough updates the variable "time01" just fine. I also put the code for delay in a comment.

clock = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: KeyFrame {
        time: 0.1s
        action: function() {
            updateclock();
        }
    }
}
function updateclock() {
    time01 = time01 + 1;
    text2.content = "Tijd: {time01 / 10}";
}


/*
delay = Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: KeyFrame {
        time: 0.1s
        action: function() {
            updatedelay();
        }
    }
}

function updatedelay() {
    time02 = time02 + 0.1;
}
*/

function control() {
    if (counter == 2) {
        /*                                    
        while (time02 < 1.2) {
            delay.play();
        }
        delay.stop();
        time02 = 0;
        */
        ..............................

Any type of help would be very much appreciated!

Was it helpful?

Solution

It's treading issue. You can't wait for something which is calculated on the same thread.

You can put code which flips card back into the Timeline to make JavaFX care about threading instead of you.

backflip : Timeline {
   repeatCount: 1
   keyFrames: KeyFrame {
        time: 1.5s
        action: function() {
           // here is code which flips card back
        }
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top