我刚开始使用 Slick2D 并了解了加载瓷砖地图并显示它是多么简单。我从众多示例中尝试了至少十几个不同的 tmx 文件,以查看它是否是损坏的实际文件。每次我得到这个错误:
Exception in thread "main" java.lang.RuntimeException: Resource not found: data/maps/desert.tmx
at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:101)
at game.Game.init(Game.java:17)
at game.Tunneler.initStatesList(Tunneler.java:37)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:164)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
at game.Tunneler.main(Tunneler.java:29)
这是我的游戏课:
package game;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tiled.TiledMap;
public class Game extends BasicGameState{
private int stateID = -1;
private TiledMap map = null;
public Game(int stateID){
this.stateID = stateID;
}
public void init(GameContainer container, StateBasedGame game) throws SlickException{
map = new TiledMap("data/maps/desert.tmx","maps");//ERROR
}
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException{
//map.render(0,0);
}
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException{
}
public int getID(){return stateID;}
}
我试图看看是否有其他人遇到过类似的问题,但没有发现任何问题。我能够加载其他文件,所以我不认为这是编译器问题。我的菜单类可以加载图像并很好地显示它们。此外,文件路径是正确的。
如果您有任何建议可以帮助我解决这个问题,请告诉我。