Jump to content
  • Advertisement
Sign in to follow this  
beebs1

Java Image

This topic is 3500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya, I have an gif image which animates once, and I'm loading it in java using the Image class, like this:
Image image = (new ImageIcon("myImage.gif")).getImage();
My problem is that if I load it multiple times for different game objects, it will only animate once, so any other game objects using the image aren't drawn. Presumably because the animation is finished. Even though I'm loading the image seperately for each object, apparently the Image class is sharing my image 'under the hood'. It might be a long shot, but does anyone know a way around this? Any help would be a saviour!

Share this post


Link to post
Share on other sites
Advertisement
I know it's a bit of a hack, but I ran into a similar problem with javascript, so I decided to just write a function that changes the frame of the animation manually, and stuck it in my game loop timer.

Kind of a pain, but it does have some advantages:

1.) You can change/branch your animations whenever you want
2.) You can use PNG for superior compression, and partial transparency

Just keep in mind that not all browsers support partial transparency of png's, so results will range from mildly annoying, to completely crippling, depending on how much you use transparency.


As for actually getting a gif animation to play multiple times, I imagine you'd probably have to completely remove it from memory, and reload it every time you want it to play... which isn't really feasible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!