1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| 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) { } } |
I think you should change:
BufferedImage[] sprites = new BufferedImage[rows * columns];
for:
BufferedImage[] sprites;
And then in the constructor add:
sprites = new BufferedImage[rows * columns];
Because when you say BufferedImage[] sprites = new BufferedImage[rows * columns];, rows and columns are 0. Then you change their values in the constructor, but sprite is already created with 0 for rown and colums, I think that's the problem
