Issues with animated GIFs

Hello, I am trying to add some animation to my game to make it a little bit more interesting to look at. I’ve made an animated gif using GIMP, but when I load the image in Eclipse it runs through the animation far faster than it is supposed to. What am I doing wrong?

Here are the relevant bits of code for assigning the image value and drawing the gif.


...

ImageIcon ii = new ImageIcon(this.getClass().getResource(src));
		image = ii.getImage();

...

public void draw(Graphics2D g2d, game.Window window){
		if(currentHP > 0)
			g2d.drawImage(getImage(), x-width/2, y-height/2, window);
	}

I do it with code, not gif. Pretty hard to implement on first time but by adjusting some parameters you can get animation that you desired

Yeah, roll the animation out to a evenly spaced sprite sheet (one big picture divided in rectangles of the same size holding the animation frames). When drawing your character, you can select one animation frame based on the time passed since the last draw call. All you have to do then, is to calculate the rectangle the desired frame is in and only draw this region to screen.

Have a looksee at this thread:

http://www.java-gaming.org/index.php/topic,19557.0.html

Put whole images of same sprite on a class as container