【发布时间】:2019-04-14 00:15:49
【问题描述】:
我在使用带有资产目录的 LibGDX 时遇到问题。我实际上构建了我的项目文件夹this way。我关注this tutorial学习。 (我在 Eclipse 上工作) 我使用的代码是:
package com.mygdx.game;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;
public class MyGdxGame implements ApplicationListener {
private SpriteBatch batch;
private TextureAtlas textureAtlas;
private Sprite sprite;
private int currentFrame = 1;
private String currentAtlasKey = new String("0001");
@Override
public void create() {
batch = new SpriteBatch();
// THE PROBLEM IS UNDER THIS LINE
textureAtlas = new TextureAtlas(Gdx.files.internal("spritesheet.atlas"));
AtlasRegion region = textureAtlas.findRegion("0001");
sprite = new Sprite(region);
sprite.setPosition(120, 100);
sprite.scale(2.5f);
Timer.schedule(new Task(){
@Override
public void run() {
currentFrame++;
if(currentFrame > 20)
currentFrame = 1;
// ATTENTION! String.format() doesnt work under GWT for god knows why...
currentAtlasKey = String.format("%04d", currentFrame);
sprite.setRegion(textureAtlas.findRegion(currentAtlasKey));
}
}
,0,1/30.0f);
}
@Override
public void dispose() {
batch.dispose();
textureAtlas.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
sprite.draw(batch);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
(如果代码难以阅读,我使用与下面链接的教程中完全相同的代码)
我的包浏览器如下所示: imgur link
它还给我:
线程“LWJGL 应用程序”com.badlogic.gdx.utils.GdxRuntimeException 中的异常:找不到文件:spritesheet.atlas(内部) 在 com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136) 在 com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.(TextureAtlas.java:103) 在 com.badlogic.gdx.graphics.g2d.TextureAtlas.(TextureAtlas.java:231) 在 com.badlogic.gdx.graphics.g2d.TextureAtlas.(TextureAtlas.java:226) 在 com.badlogic.gdx.graphics.g2d.TextureAtlas.(TextureAtlas.java:216) 在 com.mygdx.game.MyGdxGame.create(MyGdxGame.java:23) 在 com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149) 在 com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
我尝试了一些技巧,比如 Project>Clean、refresh、关闭和重新打开 Eclipse,甚至重新创建了一个项目。有什么想法吗?
【问题讨论】: