0
\$\begingroup\$

I have a 960x960 spritesheet with each tile being 192x192. I initialized my spritesheet and animation like so:

spritesheet = new SpriteSheet("resources/spritesheets/player.png", 192, 192);
walkingLeft = new Animation(spritesheet, 3, 0, 0, 1, true, 20, true);

When I attempt to render the animation, I get a java.lang.ArrayIndexOutOfBoundsException: -1 error. This error doesn't occur when I'm creating an animation from images in the same row. Therefore, I'm assuming that the error is being caused because of the way Slick is handling horizontal scanning (going to the next row after reaching the end).

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

I think you need to provide a little bit more information as you may be initialising walking left locally and then in your render method using an uninitialised variable hence the -1 response.

\$\endgroup\$
1
  • \$\begingroup\$ This isn't the problem because if I instead use walkingLeft = new Animation(spritesheet, 3, 0, 4, 0, true, 20, true); the code will work. Notice how in this case walkingLeft is initialized as an animation with 2 images in the same row in the spritesheet. \$\endgroup\$ Commented Mar 15, 2014 at 18:39
0
\$\begingroup\$

Judging from the documentation on the Animation class in slick, it looks like some of your parameters are incorrect.

frames - The sprite sheet containing the frames
x1 - The x coordinate of the first sprite from the sheet to appear in the animation
y1 - The y coordinate of the first sprite from the sheet to appear in the animation
x2 - The x coordinate of the last sprite from the sheet to appear in the animation
y2 - The y coordinate of the last sprite from the sheet to appear in the animation
horizontalScan - True if the sprites are arranged in hoizontal scan lines. Otherwise vertical is assumed
duration - The duration each frame should be displayed for
autoUpdate - True if this animation should automatically update based on the render times

As you can see, your first sprite co-ordinate is (3,0) and your last sprite co-ordinate is (0,1). If you fix this, it should stop the out of bounds error.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .