# Java Image

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

## 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 on other sites
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.