How to recolor an applet when moving a sprite?
I have a small java applet where I create 2 threads, one thread replicates and the other moves the image from the point where the user clicks. The problem is that when I call the move function it loops until the image is clicked, but it won't redraw until I break out of the loop, although the thread doing the movement and the thread doing the painting are separate.
abbreviated version of keypoints:
-
my program is an applet using paint () method
-
I have 2 threads that move the image and the other is the image
-
when i move the image it is in a while loop
-
the drawing thread still calls redraw (), but that until the call goes, it never replicates
Thank you for your time.
a source to share
It might be helpful to read the introduction of the Java AWT structure drawing system. Take a look, for example, at what Sun has: http://java.sun.com/products/jfc/tsc/articles/painting/index.html
In your case, you don't need 2 threads. The thread responsible for repainting your applet is created by AWT. It is called the Event Dispatch Thread or EDT. Thus, you just need to reposition your image, and each time you change, call the repaint method on your applet.
a source to share