This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Game! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Game!" Watch "Game!" New topic
Author

Game!

Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Hi!

Does anybody know how you precache images in memory?

In my game I create an array of pictures for an explosion, but the first time this explosion takes place it flickers A LOT... Not any other time, though.

I do like this, and when the explosion takes place I just loop through this array, switching the image to be painted.



/Kaspar
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Do the load during the initialization part of the game. Loading it at the time the user is waiting for the app to start wouldn't be real noticable.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Right now I'm trying to fill the image array in the constructor, and this is called at initialisation. This doesn't help though. The first explosion is always flickering. Would using a mediatracker help, or does anybody know of some better way?

/K
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
WHEN are you creating that object?
If it happens the first time an explosion is to take place it may be too late, if so consider creating it during program initialisation.

You may also consider preloading the actual image data to a shadow area of video memory.
That's how it's done in DirectX native programs, I don't know how you'd accomplish it in Java so you'll need to do some research into that.


42
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
The Bat object is created at Game Init, ie before the game starts. So, as far as I get it, the images should have well enough time to be loaded before the explosion takes place. Somehow, though, this does not happen...

I will look into your proposal about the DirectX way. My eyes recently fell on the BufferedImage class. Maybe I could use that somehow to buffer the images... Well... We'll see!

Thank you!

/Kaspar
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Eeeh...

For the second time, even though unsuccessful the first time, I tried using a MediaTracker. This time it worked like a charm (like I thought it would)...

The flickering gone, I can't help loving the explosions and, consequently, my graphics designer on the other side of the table... Those exps are GRREEEAAAAT!!!

Thanks for all help!

/Kaspar
 
 
subject: Game!