I'm making a game. I create an array that holds all my shapes. I need to move the shapes every 0.1 second or something small. At the same time I also have a circle following my mouse. I need to be able to move the circle following my mouse all the time but I haven't found a way to move the other circles a little bit each second. When I tried to move the other circles they would all move instantly before the javaFX window even loaded.
This is my Array
I create a circle and add it to my shape array
ArrayList<Shape> Objects = new ArrayList<Shape>();
Circle I = ClassObjects.getCircle(randomWidth,randomX,randomY);
Objects.add(I);
Ive tried to use
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(Timingobjects::myTask, 0, 1, TimeUnit.SECONDS);
}// program name, function, wait before start, time before each loop
private static void myTask() {
System.out.println("Running");
}
But I found that this is a runnable executor service so no return value can be passed out and I also can't get the array to be passed in.
Ive tried to look at callable executor service but I can't understand how to code it.
If someone could give me an example of an executable that run every 0.1 seconds and can have my shape array list passed into it so it can be altered and then returned back out.
I would be very grateful.