尝试使用纹理图集读取包文件时出现异常



这样不行吗?

    TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/texture.png"));
    AtlasRegion region = atlas.findRegion("ape_glad");
    Sprite ape= new Sprite(region);

我得到:com.badlogic.gdx.utils。GdxRuntimeException:读取包文件时出错:data/texture.png在O.o

的第一行

谢谢你的帮助!

首先,你需要创建一个纹理图集,使用TexturePacker是libgdx的推荐方法。它产生纹理图像和另一个文件(包含libgdx TextureAtlas所需的信息)。

在您的代码中,您需要向构造函数提供atlas文件,请参阅TextureAtlas()文档,而不是图像本身:

TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/texture.atlas"));

(注意这里使用了'atlas'文件而不是图像文件)

最新更新