概览 我是第一个使用我的第一个视频游戏,2D RTS的程序员。我将精灵图像存储在一个名为" Assets"的文件夹中。通过获取jar的工作目录然后搜索+" /Assets/myImage.png"来加载它们。这一切都在我自己的计算机上运行良好,而且其他人已经把它给了 - 除了一个。这个unvidual是唯一的非Windows测试程序,他运行Geltoo linux。由于某种原因,ImageIO抛出了无法加载输入图像的错误。起初也许我认为我给的是错误的目录(/ vs \或类似的东西),但我不确定了。代码如下
-units拥有一个文件数组" SpriteIcon []"它存储8个精灵,8个方向中的每一个。请注意,本机使用Main类的辅助加载这些文件(提供相关方法)。然后它运行中间代码,使用ImageIO读取文件并返回存储在其中的图像。这是抛出错误的部分。
//unit loading a sprite. spriteIcon is a file.
this.spriteIcon[i] = new File(Main.getDir() + Main.assets + "TruckSprite.png");
// Code to load the image from the File
BufferedImage img = null;
try {
//this.setSprite returns a File (loaded by the above code)
img = ImageIO.read(this.setSprite(pf.direction));
} catch (IOException e) {
e.printStackTrace();
}
return img;
}
/* MAIN CLASS */
public staic String assets = "Assets+ + File.Separator;
public static String getDir(){
String output = System.getProperty("user.dir")+File.separator;
return output;
}