这是我的来源
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
答案 0 :(得分:5)
此部分异常看似相关:
Caused by: java.io.IOException: couldn't load pixmap progressive jpeg
Libgdx不支持渐进式JPEG图像: https://code.google.com/p/libgdx/issues/detail?id=761
渐进式jpeg是专为在互联网上使用而设计的,并且设置为部分下载将提供有用的图像,随着更多信息的下载,它将逐渐变得更好(与您需要的标准jpg相比)在显示整个图像之前的图像)。桌面或Android应用程序不一定需要渐进式支持。您应该能够使用大多数图像编辑软件将此文件转换为常规jpeg。