So my trouble is that when I put this game into a .JAR file it won't show up. I can still see the bullets but I can't see the invader images
public class Invaders {
protected int xPos;
protected int yPos;
protected int moveStep = 0;
protected int size = 15;
static BufferedImage invader1image = DrawingPanel.loadBitmap("invader1.jpg");
static BufferedImage invader2image = DrawingPanel.loadBitmap("invader2.jpg");
//some code in the middle omitted
public void draw(Graphics g, int seconds) {
if(seconds%50 < 25){
g.drawImage(invader1image,
this.xPos-this.size, this.yPos-this.size,
this.size*2, this.size*2,null);
} else{ g.drawImage(invader2image, // this isn't working
this.xPos-this.size, this.yPos-this.size,
this.size*2, this.size*2,null);
}
}
you should get the images the following way
BufferedImage invader1image = ImageIO.read(getClass().getResource("invader1.jpg"));
now you keep your images along your class file
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.