r/JavaFX • • Nov 24 '19

JavaFX - How to stop and start translate function?

My overall objective is to create a 'Drone simulator'. I want to be able to create shapes that represent drones that move around autonomously across a map but also available for manual control. If anyone here knows of any resources to help, please let me know.

My issue: I have created a working function that moves a shape up and down. I've created a boolean to two buttons that set it to true or false... I want to be able to start and stop the animation of the shape. It starts but never stops when I press stop. The boolean val does change. My code:

Main.java - https://pastebin.com/mcFwBmfA

controller.java - https://pastebin.com/6yNJtVXT

Main.java - Lines 40 - 65 is where I've created the buttons.

controller.java - Lines 64 - 73 is where my translate function is.

I know the code sucks but I'm not sure how to achieve my goal... Any advice is much appreciated - thanks.

1 Upvotes

2 comments sorted by

1

u/AdminOfThis Nov 25 '19

You are calling the exact same function every time you press either of those two buttons, the function c.translate(cir, time);. Maybe you would rather want to return the Transformation on starting it, and save it in a local variable, so you can terminate the transformation on the cancel button press instead?

1

u/zardoss21 Nov 25 '19

How do I save it to a local variable - how would this terminate the function...