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
posted
0
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.
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
posted
0
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
posted
0
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!
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!!!