Alright so I’m having a little bit of trouble getting my sprite sheet loader to work.
SSL = new SpriteSheetLoader(32, 32, 5//rows, 1//columns);
package com.akrillix.client;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class SpriteSheetLoader {
BufferedImage spriteSheet = ImageIO.read(new File("src/spriteSheet.png"));
int width;
int height;
int rows;
int columns;
BufferedImage[] sprites = new BufferedImage[rows * columns];
public SpriteSheetLoader(int width, int height, int rows, int columns) throws IOException {
this.width = width;
this.height = height;
this.rows = rows;
this.columns = columns;
for(int i = 0; i < rows; i++) {
for(int j = 0; j < columns; j++) {
sprites[(i * columns) + j] = spriteSheet.getSubimage(i * width, j * height, width, height);
}
}
}
public void paint(Graphics g) {
//g.drawImage(sprites[1], 100, 100, null);
}
}
The error.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.akrillix.client.SpriteSheetLoader.<init>(SpriteSheetLoader.java:26)
at com.akrillix.client.GameWorld.<init>(GameWorld.java:25)
at com.akrillix.client.Launcher.main(Launcher.java:12)
This is my sprite sheet.