I'm following a section in a book called The Black Art of Java Game Programing, which has been a wonderful book thus far, but I encountered a problem. The images for the enemy ufo's are not loading. Currently I'm going through rechecking all the code and I just want to post it up here if anyone can help me along.
As for your problem, I'm not sure how many will want to follow a link, so let's first talk some debugging. So forgetting the game for a bit, have you been able to create a Java program that shows an image? If not, that's where I'd start -- just create as simple a program as possible whose only goal is to create and display an image, and if it fails start debugging (checking state of variables for instance with println statements). If that still fails, then post your small program here and describe any problems and post any error messages you may have.
Alec Porter wrote: Well I created a simple animation,
Some times it doubles up, is there an error with my math?
No. I don't thinks so. Please understand that you only have a limited control of when components are painted, and while your code can request a repaint, this isn't always obeyed, and often times the OS will initiate a repaint completely out of your control.
I suggest though that you move on up from AWT to Swing as it is much more robust, and also there are many more Swing experts here and elsewhere who can help you.
Yes, i agree that the math looks fine but that sometimes you are getting extra ("bonus") repaints from the system, perhaps due to the mouse movement? If the extra repaints occur during your sleep time, perhaps it won't make a big effect on the animation?
I've been experimenting with using a Timer, using that to trigger updates and repaints. You might look at that as a way to handle the desired latency without having to put your code to sleep. I've been having some success there.
(Is it okay to show off an app? http://www.adonax.com/Jean/HowWide -- this Applet draws lines in XOR mode, up to one per 25 msec when the slider starts working -- the applet is in development, something a friend of mine is designing and I'm programming it for him. During the start when it gets crazy, the Timer is kicking out RemindTasks at the rate of one per 5 msec, but I strongly suspect the redraws are getting collapsed into less frequent events.)
Alec Porter wrote: the only problem is with the out put
You kind of call the paint method when you explicitly call repaint however the system also calls paint automatically whenever the system thinks the window needs refreshing. this means paint could get called whenever.