问题
Here's my source
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);
}
}
}
I have the test.tmx file and the images inside the data folder inside assets. However, when i try to run my application I get the following error.. The vector_grass_and_sky_2_by_blackmaddog.jpg is inside the data directory but TmxMapLoader however is not able to load the files. Do I need to do anything else besides just putting the image files and the tmx files in the same place and try to load it?
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
回答1:
This part of the exception looks relevant:
Caused by: java.io.IOException: couldn't load pixmap progressive jpeg
Progressive JPEG images are not supported by Libgdx: https://code.google.com/p/libgdx/issues/detail?id=761
A progressive jpeg is one that is designed for use over the internet, and is setup such that a partial download will give a useful image and it will progressively get better as more information is downloaded (vs. standard jpg where you need most of the image before you can display a whole image). Progressive support isn't really necessary for desktop or Android apps. You should be able to use most any image editing software to convert this file to a regular jpeg.
来源:https://stackoverflow.com/questions/15582975/cannot-load-progressive-jpeg-images-in-libgdx