问题描述
下面是我的源
包com.effect.bio;进口com.badlogic.gdx.ApplicationListener;
进口com.badlogic.gdx.Gdx;
进口com.badlogic.gdx.Input;
进口com.badlogic.gdx.graphics.GL10;
进口com.badlogic.gdx.graphics.Mesh;
进口com.badlogic.gdx.graphics.OrthographicCamera;
进口com.badlogic.gdx.graphics.Texture;
进口com.badlogic.gdx.graphics.g2d.Sprite;
进口com.badlogic.gdx.graphics.g2d.SpriteBatch;
进口com.badlogic.gdx.maps.tiled.TiledMap;
进口com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
进口com.badlogic.gdx.maps.tiled.TmxMapLoader;
进口com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMa prenderer;
进口com.badlogic.gdx.math.Rectangle;公共类AppController的实现ApplicationListener {
静态最终诠释WIDTH = 480;
静态最终诠释HEIGHT = 320; 私人OrthographicCamera摄像头;
私人SpriteBatch批次;
私人纹理质感;
私人雪碧雪碧;
私人网状网格;
私人矩形glViewport;
私人浮动rotationSpeed; TiledMap类地图;
TiledMapTileLayer层;
OrthogonalTiledMa prenderer渲染器; @覆盖
公共无效创建(){
浮W = Gdx.graphics.getWidth();
浮H = Gdx.graphics.getHeight(); rotationSpeed = 0.5F; 地图=新TmxMapLoader()加载(数据/ test.tmx)。
层=(TiledMapTileLayer)map.getLayers()得到(0); INT COLS = layer.getWidth();
INT行= layer.getHeight(); 渲染=新OrthogonalTiledMa prenderer(地图,1 / 32F); 摄像头=新OrthographicCamera(宽度,高度);
camera.position.set(宽度/ 2,高度/ 2,0); glViewport =新的Rectangle(0,0,宽度,高度);
} @覆盖
公共无效的Dispose(){
} @覆盖
公共无效渲染(){
handleInput();
GL10 GL = Gdx.graphics.getGL10(); //摄像机--------------------- /
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);
} @覆盖
公共无效调整大小(INT宽度,高度INT){
} @覆盖
公共无效暂停(){
} @覆盖
公共无效简历(){
} 私人无效handleInput(){
如果(Gdx.input.isKey pressed(Input.Keys.A)){
camera.zoom + = 0.02;
}
如果(Gdx.input.isKey pressed(Input.Keys.Q)){
camera.zoom - = 0.02;
}
如果(Gdx.input.isKey pressed(Input.Keys.LEFT)){
如果(camera.position.x大于0)
camera.translate(-3,0,0);
}
如果(Gdx.input.isKey pressed(Input.Keys.RIGHT)){
如果(camera.position.x< 1024)
camera.translate(3,0,0);
}
如果(Gdx.input.isKey pressed(Input.Keys.DOWN)){
如果(camera.position.y大于0)
camera.translate(0,-3,0);
}
如果(Gdx.input.isKey pressed(Input.Keys.UP)){
如果(camera.position.y< 1024)
camera.translate(0,3,0);
}
如果(Gdx.input.isKey pressed(Input.Keys.W)){
camera.rotate(-rotationSpeed,0,0,1);
}
如果(Gdx.input.isKey pressed(Input.Keys.E)){
camera.rotate(rotationSpeed,0,0,1);
}
}
}
我有test.tmx文件,其内部资产数据的文件夹中的图像。然而,当我尝试运行我的应用程序出现以下错误。该vector_grass_and_sky_2_by_blackmaddog.jpg是数据目录内但却TmxMapLoader无法载入的文件。我需要做任何事情除了刚刚把图像文件和TMX文件在同一个地方,并尝试加载它?
异常螺纹LWJGL应用com.badlogic.gdx.utils.GdxRuntimeException:无法加载文件:数据/ vector_grass_and_sky_2_by_blackmaddog.jpg
在com.badlogic.gdx.graphics.Pixmap<&初始化GT;(Pixmap.java:140)
在com.badlogic.gdx.graphics.glutils.FileTextureData。prepare(FileTextureData.java:64)
在com.badlogic.gdx.graphics.Texture.load(Texture.java:175)
在com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
在com.badlogic.gdx.graphics.Texture<&初始化GT;(Texture.java:133)
在com.badlogic.gdx.graphics.Texture<&初始化GT;(Texture.java:126)
在com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:106)
在com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:88)
在com.effect.bio.AppController.create(AppController.java:41)
在com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:130)
在com.badlogic.gdx.backends.lwjgl.LwjglApplication $ 1.run(LwjglApplication.java:110)
java.io.IOException异常:引起无法加载像素图渐进式JPEG
在com.badlogic.gdx.graphics.g2d.Gdx2DPixmap<&初始化GT;(Gdx2DPixmap.java:57)
在com.badlogic.gdx.graphics.Pixmap<&初始化GT;(Pixmap.java:138)
... 10个
异常的这一部分看起来相关的:
产生的原因:java.io.IOException异常:无法加载像素图渐进式JPEG
渐进JPEG图像不被支持Libgdx:
<一href=\"https://$c$c.google.com/p/libgdx/issues/detail?id=761\">https://$c$c.google.com/p/libgdx/issues/detail?id=761
一个渐进式JPEG是设计用于在互联网之一,是设置使得部分下载会给出一个有用的图像,它会逐步得到更好的为更多信息下载(相对于标准JPG格式,你最需要的图像才能显示整幅画面)。渐进式的支持是不是台式机或Android应用程序真的有必要。您应该能够使用几乎任何图像编辑软件到这个文件转换为常规JPEG。
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
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.
这篇关于无法加载在libgdx渐进JPEG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!