Reputation: 189
I have a rectangle in a Scene that I want to translate on a linear path in JavaFX using a timer. For every mSecs milliseconds, I want the rectangle to translate d distance, along an xy plane in JavaFX. I know how to simply translate something using rec.setX(x) and rec.setY(y), and having it move around. I don't want to use animations or any complicated class, I just want a timer to start, and every time it ticks a certain increment, I want to translate that rectangle a certain amount. Simple, basic animation like a flipbook. Could anyone help and/or refer me to a proper class API?
Upvotes: 0
Views: 227
Reputation: 18415
Put the Rectangle on the Scene. Calculate dx and dy depending on your start and end point, or in your case depending on d and the angle. Use an AnimationTimer as your (game) loop. Increment x and y by dx and dy in every animation frame until the Rectangle reaches the destination.
Upvotes: 1