我剛開始使用Slick2D,並瞭解到加載瓷磚地圖並顯示它的過程非常簡單。我嘗試了大量示例中的至少十幾個不同的tmx文件,以查看它是否是已損壞的實際文件。每次我得到這個錯誤:java slick無法加載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;}
}
我想看看是否有人有類似的問題,但沒有打開任何東西。我能夠加載其他文件,所以我不相信這是一個編譯器問題。我的菜單類可以加載圖像並顯示它們。另外,文件路徑是正確的。
請讓我知道,如果你有任何可以幫助我解決這個問題的指針。