• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Game!

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic