problem with Slick2D animations [fixed]

Hi guys, I’m a bit desperate here, hope you can help me or guide me in the right direction. The thing is that I’m trying to load the animations for the weapons of the main char (the game is a sidescroller metal-slug style), so, in the constructor i load all the animations on an arrayListHashMap, one for each weapon, i’ll make a weapon class eventually but i wanted to try the code first, i have a 128x128 spritesheet for 4 animations, 4 32x32 frames each.

SpriteSheet escopetass =new SpriteSheet("sprites/SHOTGUN_SHEET_128x128.png",32,32);
			escopeta.put("still", new Animation(new SpriteSheet("sprites/SHOTGUN_STILL.png",32,32),1));
			escopeta.put("boobingLeft",new Animation(escopetass,3,2,0,2,true,250,true));
			escopeta.put("boobingRight",new Animation(escopetass,0,0,3,0,true,250,true));			
			escopeta.put("shootingRight",new Animation(escopetass,0,1,3,1,true,100,true));						
			escopeta.put("Leftshooting",new Animation(escopetass,0,3,3,3,true,100,true));
		

I have the same block code for the other weapons as well,just changing the spritesheet, then in the draw method, i draw the animation depending the facing of the character, controlled with 2 booleans (facingLeft and facingRight)
when i try to run the game, i get an outOfBounds error on the animation class of slick2D.

}else if (facingLeft)
		{
			if (arma.get("Leftshooting").isStopped())
			{		
				shooting=false;
				arma.get("Leftshooting").restart();
			}
			if (shooting){
			//its firing
				player.get("still"). getCurrentFrame().getFlippedCopy(true, false).draw(this.x,this.y);
				arma.get("Leftshooting").draw(this.x,this.y);
			
			}else if (this.isMoving() && !shooting){
			//its moving				
				player.get("leftWalking").draw(this.x,this.y);
				arma.get("boobingLeft").draw(this.x,this.y); //<----- Having problems in ths line

arma its an arrayListHashmap that contains the anims of the equipped weapon on that moment.

The error:[quote]Fri Sep 09 02:57:19 CEST 2011 ERROR:-1
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.get(Unknown Source)
at org.newdawn.slick.Animation.getWidth(Animation.java:412)
at org.newdawn.slick.Animation.draw(Animation.java:326)
at com.PlayerEntity.draw(PlayerEntity.java:170)
at com.Game.render(Game.java:145)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:681)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at com.Game.main(Game.java:46)
Fri Sep 09 02:57:19 CEST 2011 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:684)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at com.Game.main(Game.java:46)
[/quote]
Hope you can help me, its driving me nuts.
Thanks in advance :slight_smile:

(I’m not sure if this is the right place for the post, if it is not, move it to the right place please)

[quote]at java.util.ArrayList.get(Unknown Source)
[/quote]
for one reason, you give -1 as index to an arraylist. check the index value by print it on run

It seems that for some strange reason, it refuses to add the images for the “boobingLeft” animation, and the index for every image is -1. The funny thing is that that animation is on the third row and should be ok, and even changing the x and y of the images to the first row for example still give me the same error. I tried changing the name of the animation, changing the coords, changing the order, since I’m doing it backwards, I even made a new 256x256 sheet with all the weapons animations and still nothing.

Trying to print out the index still gives me the same outOfBounds error.

update: Using a single spritesheet just for the boobingleft animation works fine, but it misses the point of using spritesheets at all, this is really pissing me off >:(, also, adding this code to the end of the draw method

try {
			
			new SpriteSheet("sprites/WEAPONS_SHEET_256x256.png",32,32).getSprite(4,6).draw(150,279);
		
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

draws the correct image just fine.

Another Update: I think i got it, the problem its that i can’t scan a spritesheet backwards because the first x argument is the 0 index in the arraylist of the animation, scanning to the left would be like going to the index -1.

Soooo yeah, it was that, i change the spritesheet and now works properly, Thanks ReBirth for the reply!!

Cheers!

ROFL!! I just died of laughter. :smiley: