我正在关注 youtube 上的教程,当我到达我应该使用“this.path”之类的部分时,但我似乎遇到了错误。我似乎找不到任何解决方案。
这是视频的链接:http ://www.youtube.com/watch?v=o7pfq0W3e4I
package gfx;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class SpriteSheet {
public String path;
public int width;
public int height;
public int[] pixels;
public SpriteSheet(String path) {
BufferedImage image = null;
try {
image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
}
if(image == null);{
return;
}
this.path = path;
this.width = image.getWidth();
this.height = image.getHeight();
pixels = image.getRGB(0, 0, width, height, null, 0, width);
for(int i = 0; i <= pixels.length;i++){
pixels[i] = (pixels[i] & 0xff)/64;
}
for(int i = 0;i <= 8;i++) {
System.out.println(pixels[i]);
}
}
}