当bigImg
成为它确实显示的图像时,但当sprites[dir]
成为图像时它不会显示。
在跑步时,我画了一个小盒子来显示精灵的位置,里面什么都没有。
public void getSprite(){
BufferedImage bigImg = null;
try {
bigImg = ImageIO.read(new File("Pacman.png"));
} catch (IOException e) {
System.out.println("hey");
e.printStackTrace();
}
// The above line throws an checked IOException which must be caught.
final int width = 7;
final int height = 7;
final int rows = 4;
final int cols = 3;
BufferedImage[] sprites = new BufferedImage[rows * cols];
System.out.println(bigImg.getHeight() + "," + bigImg.getWidth());
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
sprites[(i * cols) + j] = bigImg.getSubimage(
j * width,
i * height,
width,
height
);
}
}
//image = bigImg;
}
public void setSprite (int direction){
System.out.println("HEY");
System.out.println(sprites[1].getHeight());
image = sprites[direction];
}