gpt4 book ai didi

exception - Slick2D可运行 jar (JarSplice)找不到声音 Assets ? “Resource not found”错误

转载 作者:行者123 更新时间:2023-12-03 02:19:48 24 4
gpt4 key购买 nike

我昨天才刚开始制作Slick2D游戏,在我添加声音之前一切都还不错。游戏本身在 eclipse 中运行良好,并且声音按预期播放。但是,当我将其编译为jar文件,然后使用JarSplice编译为胖jar时,生成的可运行jar会在几分之一秒的时间内打开游戏窗口,然后崩溃。如果从命令提示符运行jar,则可以看到返回的错误是:

错误:找不到资源:Assets / Sound / THRUST.wav
Java.lang.RuntimeException:找不到资源:Assets / sound / THRUST.wav

...等等。我检查了jar文件,并成功添加了所有声音文件。我也尝试过构建不带声音代码的jar,并且效果很好,因此图像资源可以正确加载。它只具有健全 Assets 的问题。这是我的代码:

package starMiner;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;


import org.newdawn.slick.*;


public class StarMiner extends BasicGame
{
static AppGameContainer app;
static int resX=800;
static int resY=600;
Image bg = null;
Image playerShip = null;
Image shipMove = null;
Image shipIdle = null;
float x = 0;
float y = 0;
float scale = 1.0f;
float xMomentum = 0;
float yMomentum = 0;
float speed = 0;
Sound fuel,engine;


public StarMiner()
{
super("StarMiner");
}

@Override
public void init(GameContainer gc) throws SlickException
{
bg = new Image("Assets/stars.png");
playerShip = new Image("Assets/starship.png");
shipIdle = new Image("Assets/starship.png");
shipMove = new Image("Assets/starshipgo.png");
fuel = new Sound("Assets/sound/THRUST.wav");
engine = new Sound("Assets/sound/engine.wav");

}

@Override
public void update(GameContainer gc, int delta) throws SlickException
{
Input input = gc.getInput();

if(input.isKeyDown(Input.KEY_LEFT))
{
playerShip.rotate(-0.1f * delta);
}

if(input.isKeyDown(Input.KEY_ESCAPE))
{
app.exit();
}

if(input.isKeyDown(Input.KEY_F4))
{
app.setFullscreen(!app.isFullscreen());
}

if(input.isKeyDown(Input.KEY_RIGHT))
{
playerShip.rotate(0.1f * delta);
}

if(input.isKeyDown(Input.KEY_UP))
{
playerShip.setTexture(shipMove.getTexture());
float hip = 0.4f * delta;

float rotation = playerShip.getRotation();

xMomentum+= hip * Math.sin(Math.toRadians(rotation));
yMomentum-= hip * Math.cos(Math.toRadians(rotation));
if(!fuel.playing()){fuel.play();}
}
else
{
fuel.stop();
playerShip.setTexture(shipIdle.getTexture());
}

if(input.isKeyDown(Input.KEY_DOWN))
{
float hip = 0.4f * delta;

float rotation = playerShip.getRotation();

xMomentum-= hip * Math.sin(Math.toRadians(rotation));
yMomentum+= hip * Math.cos(Math.toRadians(rotation));
}
x+=xMomentum/800;
y+=yMomentum/800;


xMomentum-=(xMomentum)/1300;
yMomentum-=(yMomentum)/1300;
if(Math.abs(xMomentum)<.000001){xMomentum=0;}
if(Math.abs(yMomentum)<.000001){yMomentum=0;}

speed = (float) Math.sqrt((0-xMomentum)*(0-xMomentum) + (0-yMomentum)*(0-yMomentum));
if(!engine.playing()){engine.play();}

}

@Override
public void render(GameContainer gc, Graphics g) throws SlickException
{
int xDif = 640;
int yDif = 480;
int pModx = (int) ((x*.8)%xDif);
int pMody = (int) ((y*.8)%yDif);
int bgExt = 4*(resX/800);
for(int i = -(bgExt/2)+1; i <= bgExt/2; i++)
{
for(int j = -(bgExt/2)+1; j <= bgExt/2; j++)
{
bg.draw(((resX/2)-16)-pModx-(xDif*i), ((resY/2)-16)-pMody-(yDif*j));
}
}
bg.draw(((resX/2)-16)-pModx, ((resY/2)-16)-pMody);
bg.draw(((resX/2)-16)-pModx-xDif, ((resY/2)-16)-pMody);
bg.draw(((resX/2)-16)-pModx-xDif, ((resY/2)-16)-pMody-yDif);
bg.draw(((resX/2)-16)-pModx, ((resY/2)-16)-pMody-yDif);
playerShip.draw(((resX/2)-16), ((resY/2)-16), scale);
g.drawString("x: "+x, 10, 50);
g.drawString("y: "+y, 10, 70);
g.drawString("xMomentum: "+xMomentum, 10, 90);
g.drawString("yMomentum: "+yMomentum, 10, 110);
g.drawString("angle: "+playerShip.getRotation(), 10, 130);
g.drawString("speed: "+speed, 10, 150);

}

public static void main(String[] args) throws SlickException
{
app = new AppGameContainer(new StarMiner());

app.setDisplayMode(resX, resY, false);
app.start();
}
}

提前致谢!

最佳答案

如果您尝试将Asset文件夹放在生成的.jar旁边(与.jar放在同一文件夹中,而不是.jar内),该怎么办?

关于exception - Slick2D可运行 jar (JarSplice)找不到声音 Assets ? “Resource not found”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15056735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com