0

I'm creating a circle and the circle needs to be moved around on the GUI every second or so and be continuous. What do I need to implement in the code for that to happen?

I can get it to move to the position, but after it gets to that position it stops and i need it to be continuous.

Circle c1 = new Circle(250,250,100);
c1.setFill(Color.YELLOW);


timeline = new Timeline(new KeyFrame(Duration.seconds(.5),new     KeyValue(c1.centerXProperty(),100)));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();

root.getChildren().addAll(c1);
primaryStage.setScene(scene);
primaryStage.show();
  • `c1.setCenterX(c1.getCenterX() + 10);` – SedJ601 Apr 24 '19 at 20:18
  • have a look at this `Timeline` to make sure you have implemented yours correctly. https://stackoverflow.com/questions/9966136/javafx-periodic-background-task – SedJ601 Apr 24 '19 at 20:19
  • Okay so using this it seems to get the animation down that i want, but i want to keep it on the GUI screen instead of it moving off of the screen if that makes sense. Sort of moving in a pattern i guess instead of relocating the circle until it is off the screen – tristan howard Apr 24 '19 at 23:03
  • @Sedrick^ meant to tag you in this. – tristan howard Apr 24 '19 at 23:11
  • 1
    Code wise, I don't know how, but maybe run the process while monitoring the values using a `System.out.println()`, once it reaches a place you don't want it to be, write that value down. Afterwards put the whole process in a `while loop` and let it run till it reaches the above mentioned value - when it does, if you're using "+" to move it, switch it to "-" so it would move backwards till it reaches the place of origin and then make it go back to "+". Not sure if I'm explaining myself well. :D – Doombringer Apr 25 '19 at 00:48
  • You can get some ideas from https://github.com/sedj601/PongFX – SedJ601 Apr 25 '19 at 03:30

0 Answers0