wood burning stoves*
The moose likes Game Development and the fly likes Need help with my game. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Need help with my game." Watch "Need help with my game." New topic
Author

Need help with my game.

Alec Porter
Greenhorn

Joined: Sep 05, 2010
Posts: 29
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.

Here's the download link, I created it in JCreator but you can use the java files if you don't have it.
http://www.mediafire.com/?llnpdu5grbjya98

Thanks a bunch.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Hello and welcome to JavaRanch!

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.

Much luck and again welcome!
Alec Porter
Greenhorn

Joined: Sep 05, 2010
Posts: 29
Well I created a simple animation,



the only problem is with the out put



Some times it doubles up, is there an error with my math?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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.
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
Hi - Greenhorn alert! (That's ME, tossing in a few suggestions.)

You might check out this article "Painting in AWT and Swing":
http://java.sun.com/products/jfc/tsc/articles/painting/

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.)

Mich Robinson
Ranch Hand

Joined: Jun 28, 2009
Posts: 250
    
    1
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.


Arcade : Alien Swarm
Board : Chess - Checkers - Connect 4 - Othello
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with my game.
 
Similar Threads
How long does it usually take beginning java learners to be able to start their first full game?
Game development books/recommendations
Head First Java Ready-Bake Code
Which book do you recommend?
Graphics Lag on Certain Computers