我正在学习使用 libGDX 的 Java 平铺游戏教程,但遇到以下错误:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: gaming creation/herbe16.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:142)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:112)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:108)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:119)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:104)
at com.poussins.screens.Play.show(Play.java:35)
at com.badlogic.gdx.Game.setScreen(Game.java:62)
at com.poussins.Poussins.create(Poussins.java:11)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: gaming creation/herbe16.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:133)
at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:563)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
... 12 more
这是我在 Play 类中使用的代码:
package com.poussins.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
public class Play implements Screen{
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;
private OrthographicCamera camera;
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.setView(camera);
renderer.render();
}
@Override
public void resize(int width, int height) {
camera.viewportWidth = width;
camera.viewportHeight = height;
camera.update();
}
@Override
public void show() {
map = new TmxMapLoader().load("maps/map-Herbe-Goudron.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
camera = new OrthographicCamera();
}
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
map.dispose();
renderer.dispose();
}
}
为了将 .tmx 映射到 Eclipse 项目中,我只是制作了一个副本(从 .tmx 映射所在的文件夹)并粘贴到名为“Poussins-Desktop / assets / maps”的 Eclipse 项目中。我使用相同的操作(复制粘贴)将 .png 切片提供给名为“Poussins-Desktop / assets / maps”的同一个 Eclipse 项目(可以在屏幕截图中看到)。在代码中,我不确定以下行:
map = new TmxMapLoader().load("maps/map-Herbe-Goudron.tmx");
因为我不知道.tmx的路径是否好,但它似乎尊重教程中所说的......
实际上,在错误中,是说无法加载文件herbe16.png。但这个文件是整个 .tmx 地图的一个图块。
我正在开发 UBUNTU 13.10 系统,Eclipse 3.8.1
我希望有人能帮助我,我提前感谢你关注我的问题。