简体   繁体   English

在 Eclipse 中将项目构建为可执行 jar 文件时,缓冲图像不呈现

[英]Buffered Images not rendering when project is built as an executable jar file in eclipse

So, I'm working on a 2D tile based game for my programming class.所以,我正在为我的编程课开发一个基于 2D 瓷砖的游戏。 I've gotten the basics done with rendering images and moving in game.我已经完成了渲染图像和在游戏中移动的基础知识。 All my images work when I run the project in eclipse.当我在 Eclipse 中运行项目时,我所有的图像都可以工作。 When I build it as an executable jar file, none of the images show up.当我将它构建为一个可执行的 jar 文件时,没有任何图像显示出来。

This is what it should look like (when I run it in eclipse with my current set up) What is should look like这就是它应该是什么样子(当我使用当前设置在 eclipse 中运行它时)应该是什么样子

This is what happens when I run the executable jar.这就是我运行可执行 jar 时发生的情况。 What I get我得到的

My images are loaded in assets class like so:我的图像加载到资产类中,如下所示:

SpriteSheet sheet = new SpriteSheet(ImageLoader.ImageLoader("/textures/sheet.png"));

Here is Image Loader:这是图像加载器:

public class ImageLoader 
{
public ImageLoader()
{

}
public static BufferedImage ImageLoader(String path)
{
    try {
        return ImageIO.read(ImageLoader.class.getResource(path));
    } catch (IOException ex) {
        ex.printStackTrace();
        System.exit(1);
    }
    return null;
}
}

The two folders I have specified in the build path are src and res.我在构建路径中指定的两个文件夹是 src 和 res。 I know that it is building the images into the jar as i can see them if i extract it.我知道它正在将图像构建到 jar 中,因为如果我提取它,我可以看到它们。

Any idea as to what I messed up on?知道我搞砸了什么吗?

Pretty sure u need to add a Res folder to the build path.很确定你需要在构建路径中添加一个 Res 文件夹。

The Res folder is where all your sprite sheets should be. Res 文件夹是您所有精灵表的位置。

Right click your project and edit build path.右键单击您的项目并编辑构建路径。

Try adding the textures folder to your build path尝试将纹理文件夹添加到您的构建路径

EDIT The folder doesn't need to be named "Res"编辑文件夹不需要命名为“Res”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM