Eclipse导出Runnable Jar文件,图像不工作

时间:2017-06-07 12:22:20

标签: java

我正在制作包含图像的2D平台,当它在Eclipse IDE中编译时,它很好并且运行完美。但是,当我将它导出到Runnable Jar文件时,它根本不起作用。有什么解决方案吗?我已经阅读了很多类似于我的其他案例,但所有解决方案都不适用于我的情况。我将保留下面的主要代码。

private static final long serialVersionUID = 1L;

private boolean running = false;
private Thread thread; 

public static int WIDTH, HEIGHT;

public BufferedImage level = null, clouds = null, level2 = null;

//Object
Handler handler;
Camera cam;
static Texture tex;

public static int LEVEL = 1;

private void init(){
    WIDTH = getWidth();
    HEIGHT = getHeight();

    tex = new Texture();

    BufferedImageLoader loader = new BufferedImageLoader();
    level = loader.loadImage("/level.png"); //loading the level
    clouds = loader.loadImage("/bkg_clouds.png"); // loading backgroundd

    cam = new Camera(0, 0);
    handler = new Handler(cam);

    handler.LoadImageLevel(level);

    //handler.addObject(new Player(100, 100, handler,  ObjectID.Player));

    //handler.createLevel();

    this.addKeyListener(new KeyInput(handler));
}

public synchronized void start(){
    if(running)
        return;

    running = true;
    thread = new Thread(this);
    thread.start();
}

public void run(){
    init();
    this.requestFocus();
    long lastTime = System.nanoTime();
    double amountOfTicks = 60.0;
    double ns = 1000000000 / amountOfTicks;
    double delta = 0;
    long timer = System.currentTimeMillis();
    int updates = 0;
    int frames = 0;
    while(running){
        long now = System.nanoTime();
        delta += (now - lastTime) / ns;
        lastTime = now;

        while(delta >= 1){
            tick();
            updates++;
            delta--;
        }

        render();
        frames++;

        if(System.currentTimeMillis() - timer > 1000){
            timer += 1000;
            System.out.println("FPS: " + frames + " || TICKS: " + updates);
            frames = 0;
            updates = 0;
        }
    }
}

private void tick(){
    handler.tick();
    for(int i = 0; i < handler.object.size(); i++){
        if(handler.object.get(i).getID() == ObjectID.Player){
            cam.tick(handler.object.get(i));
        }
    }
}

private void render(){
    BufferStrategy bs = this.getBufferStrategy();

    if(bs == null){
        this.createBufferStrategy(3);
        return;
    }

    Graphics g = bs.getDrawGraphics();
    Graphics2D g2d = (Graphics2D) g;


    //Draw Here
    g.setColor(new Color(15, 191, 224));
    g.fillRect(0, 0, getWidth(), getHeight());


    g2d.translate(cam.getX(), cam.getY()); //being of camera

    for(int xx = 0; xx < clouds.getWidth() * 3; xx += clouds.getWidth())
        g.drawImage(clouds, 200, 50, 214, 130, this);
        g.drawImage(clouds, 600, 50, 214, 130, this);
        g.drawImage(clouds, 2000, 50, 214, 130, this);
        g.drawImage(clouds, 3000, 50, 214, 130, this);

        handler.render(g);

    g2d.translate(-cam.getX(), -cam.getY()); //end of camera

    g.dispose();
    bs.show();

}

public static Texture getInstance(){
    return tex;
}

public static void main(String args[]){
    new Window(800, 600, "Space Stranded", new Game2D());
}

}

0 个答案:

没有答案