java - JavaFx display image instantly -


im making memory card game.

i want able catch 2 clicks, display them , compare them.

i tried achieve doesn't work way want it. code ive written waits 2 clicks, displays first card , secound card never displays because right away when got 2 cards compare them, , if aren't same remove both cards.

  eventhandler<mouseevent> keyeventhandler =             new eventhandler<mouseevent>() {                 @override                 public void handle(mouseevent event) {                     clickedcards(event);                     if (klickade.size() == 2) {                         boolean issame = cardsaresame();                         if (issame) {                             firstmemorycard.setpair(boolean.true);                             secoundmemorycard.setpair(boolean.true);                             klickade.clear();                         } else {                             firstmemorycard.setgraphic(firstmemorycard.getimagefacedown());                             secoundmemorycard.setgraphic(secoundmemorycard.getimagefacedown());                             klickade.clear();                         }                     }                 }             };  public void clickedcards(mouseevent event) {     memorycard memorycard = (memorycard) event.getsource();     klickade.add(memorycard);     memorycard.setgraphic(memorycard.getimagefaceup());      system.out.println(klickade.size()); } 

i think asking how can put delay in code before show result of user's guess.

the easiest way use pausetransition:

if (klickade.size() == 2) {     pausetransition pause = new pausetransition(duration.seconds(1));     pause.setonfinished(event -> {         boolean issame = cardsaresame();         if (issame) {             firstmemorycard.setpair(boolean.true);             secoundmemorycard.setpair(boolean.true);             klickade.clear();         } else {             firstmemorycard.setgraphic(firstmemorycard.getimagefacedown());             secoundmemorycard.setgraphic(secoundmemorycard.getimagefacedown());             klickade.clear();         }     });     pause.play(); } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -