Effective animation design, anyone ?
Hi all !
I would like to check if there would be any good solutions for the following out here as I'm sure you've done a lot more intense painting on screen than this.
Btw. I'm sorry that I don't have a fully functioning example with this but haven't extracted it out of the rest of my code, yet (divided into a few classes).
I have an animation on screen where a competitor runs around on a map. The competitor is represented by a filled circle and the map is drawn as an image on screen.
To know how the competitor moves around on the screen there is an array of Points which represents every pixel that the competitor moves along. In other words for each 50 ms iteration the competitor moves once to the next Point on the screen. This because we want to have an exact route on the screen and hence each point "touches" the previous and next Point on the screen.
Now, we multiply this with up to 100 simultaneous competitors on the screen and we are close to reality.
This is fine and works o.k. but now if I would like to paint the already travelled or even the full route of the competitor on the screen the fun begins.
Now the short and simple question:
What is the most effective way to paint the trail after the competitor without running out of CPU?
For a bit longer analysis read below (but the question remains pretty much the same):
I have practically thought of three different ways of doing this:
1. For each paint call iterate through the Point array and paint each pixel as a small circle on the screen.
+ easy to do
- Kills the CPU as we do this 20 times a second and the Point array can be up to 5000 points long.
2. Create a second "layer" and paint the route on that one. Hence you just need to add the points and not repaint the whole thing for each loop.
+ Should be good performance
- JLayeredPane is the only way I might achieve this but the application contains so many JScrollPanes, JPanels, eventhandlers etc. that haven't still figured out why the repainting just messes things up (so the problem is that it seems to be not having enough BrainPower to figure out how to work with the darn thing).
- Not certain if my assumption is correct. Will layers allow me not to repaint the other layers if i repaint some ?
3. Draw the whole route at once on the underlying image
+ only do it once, should not be a performance issue after the initial drawing.
- The line does not follow the competitor bu the competitor ends up moving on the predrawn line.
Now, of course might be that my initial implementation is wrong, but haven't found out any better way to do this either.

