简体   繁体   中英

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. I've gotten the basics done with rendering images and moving in game. All my images work when I run the project in eclipse. When I build it as an executable jar file, none of the images show up.

This is what it should look like (when I run it in eclipse with my current set up) What is should look like

This is what happens when I run the executable 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. I know that it is building the images into the jar as i can see them if i extract it.

Any idea as to what I messed up on?

Pretty sure u need to add a Res folder to the build path.

The Res folder is where all your sprite sheets should be.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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