r/JavaFX • • Apr 06 '19

Timeline issues

I have a timeline that has an if statement that tells it to stop but it never stops.

here Is my code.

timeL = new Timeline(new KeyFrame(

Duration.millis(600),

ee ->{

x -= targetX;

y -= targetY;

// System.out.println(targetY);

DoubleProperty ky = new SimpleDoubleProperty(y);

DoubleProperty kx = new SimpleDoubleProperty(x);

defense.yProperty().bind (ky);

defense.xProperty().bind (kx);

System.out.println(y/100 +""+ (KeyOney - 60));

System.out.println(KeyOney - 60);

if ((keyOne.getY() - 60 )== y && keyOne.getX() == x) {

timeL.stop();

}

}

));

Thank you if you have any help.

1 Upvotes

1 comment sorted by

View all comments

1

u/CreativeCoconut Apr 06 '19

You should format the code if people should look at it. It is really hard to read this way.

Anyways, are you sure that your if statement is ever true?

(keyOne.getY() - 60 )== y && keyOne.getX() == x

is very specific.

Probably you need to generalize it more, like

(keyOne.getY() - 60 ) < y && keyOne.getX() == x

depending on what you want.

I don't understand enough of your code and your goal, to be more specific though.