This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Need help with my game.

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 137
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)

 
Ranch Hand
Posts: 275
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
    Bookmark Topic Watch Topic
  • New Topic