• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Game!

 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic