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
(I’m not sure if this is the right place for the post, if it is not, move it to the right place please)