当我想在Android Studio中加载我的.tmx文件时出现: level1.tmx文件(例如tileset_gutter.png)都在assets目录中。但我从未在我的代码中声明tileset_gutter.png,为什么它会显示错误呢?有什么建议吗?
E/AndroidRuntime: FATAL EXCEPTION: GLThread 96347
Process: com.fraggy, PID: 15481
com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: Pictures/tileset_gutter.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:148)
at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:96)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:84)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:65)
at com.fraggy.Screens.PlayScreen.<init>(PlayScreen.java:41)
at com.fraggy.MainActivity.create(MainActivity.java:21)
at
.....
这是我的代码:你可以看到
public class PlayScreen implements Screen {
private MainActivity game;
private OrthographicCamera gamecam;
private Viewport gamePort;
private Hud hud;
private TmxMapLoader maploader;
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;
public PlayScreen(MainActivity game){
this.game = game;
gamecam = new OrthographicCamera();
gamePort = new FitViewport(MainActivity.V_WIDTH, MainActivity.V_WEIGHT, gamecam) ;
hud = new Hud(game.batch);
maploader = new TmxMapLoader();
map = maploader.load("level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
gamecam.position.set(gamePort.getWorldWidth()/2, gamePort.getWorldHeight()/2, 0);
}
public void update(float dt){
handleInput(dt);
gamecam.update();
renderer.setView(gamecam);
}
private void handleInput(float dt) {
if (Gdx.input.isTouched())
gamecam.position.x += 100*dt;
}
答案 0 :(得分:1)
用于TMX文件(平铺图)的图像嵌入在地图文件中。默认的libgdx加载程序还会加载tmx文件中定义的映像。