这是我的来源
package com.effect.bio;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Rectangle;
public class AppController implements ApplicationListener {
static final int WIDTH = 480;
static final int HEIGHT = 320;
private OrthographicCamera camera;
private SpriteBatch batch;
private Texture texture;
private Sprite sprite;
private Mesh mesh;
private Rectangle glViewport;
private float rotationSpeed;
TiledMap map;
TiledMapTileLayer layer;
OrthogonalTiledMapRenderer renderer;
@Override
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
rotationSpeed = 0.5f;
map = new TmxMapLoader().load("data/test.tmx");
layer = (TiledMapTileLayer) map.getLayers().get(0);
int cols = layer.getWidth();
int rows = layer.getHeight();
renderer = new OrthogonalTiledMapRenderer(map, 1/32f);
camera = new OrthographicCamera(WIDTH, HEIGHT);
camera.position.set(WIDTH/2, HEIGHT/2, 0);
glViewport = new Rectangle(0, 0, WIDTH, HEIGHT);
}
@Override
public void dispose() {
}
@Override
public void render() {
handleInput();
GL10 gl = Gdx.graphics.getGL10();
// Camera --------------------- /
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glViewport((int) glViewport.x, (int) glViewport.y,
(int) glViewport.width, (int) glViewport.height);
camera.update();
camera.apply(gl);
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
private void handleInput() {
if(Gdx.input.isKeyPressed(Input.Keys.A)) {
camera.zoom += 0.02;
}
if(Gdx.input.isKeyPressed(Input.Keys.Q)) {
camera.zoom -= 0.02;
}
if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
if (camera.position.x > 0)
camera.translate(-3, 0, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
if (camera.position.x < 1024)
camera.translate(3, 0, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
if (camera.position.y > 0)
camera.translate(0, -3, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.UP)) {
if (camera.position.y < 1024)
camera.translate(0, 3, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.W)) {
camera.rotate(-rotationSpeed, 0, 0, 1);
}
if(Gdx.input.isKeyPressed(Input.Keys.E)) {
camera.rotate(rotationSpeed, 0, 0, 1);
}
}
}
我在资产内的数据文件夹中有 test.tmx 文件和图像。但是,当我尝试运行我的应用程序时,出现以下错误。vector_grass_and_sky_2_by_blackmaddog.jpg 在数据目录中,但是 TmxMapLoader 无法加载文件。除了将图像文件和 tmx 文件放在同一个地方并尝试加载它之外,我还需要做任何其他事情吗?
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/vector_grass_and_sky_2_by_blackmaddog.jpg
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:175)
at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:126)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:106)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:88)
at com.effect.bio.AppController.create(AppController.java:41)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:130)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
Caused by: java.io.IOException: couldn't load pixmap progressive jpeg
at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:57)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:138)
... 10 more