Libgdx,TextureAtlas(.pack)通过AssetManager

时间:2014-09-16 07:39:11

标签: java android libgdx

我最初直接从资产文件夹中实现了加载TextureAtlas但是 由于我必须调用TextureAtlas的每个区域以用于动画中的帧(libgdx声明使用了Find区域的TextureAtlas是SLOW =滞后),因此游戏变得非常滞后。所以我决定使用assetloader来减少延迟,但问题是 我找不到通过AssetManager加载TextureAtlas(.pack)的方法。我一直在接受

com.badlogic.gdx.utils.GdxRunTimeException:未加载的资产:enemytest.pack

我一直在尝试使用其他装载机,但它没有顺利......我找不到任何资源,所以我需要帮助:( 提前谢谢你!

在我的资源文件夹中,我有“enemytest.png”和“enemytest.pack”文件。

这是一个游戏类(扩展游戏)

public class MyGdxGame extends Game {

    private TextureAtlas enemy;
    AssetManager manager;
    FileHandleResolver resolver = new InternalFileHandleResolver();

    @Override
    public void create () {

        manager = new AssetManager();
        manager.setLoader(TextureAtlas.class, new TextureAtlasLoader(new InternalFileHandleResolver()));
        load();

        setScreen(new GameScreen());
    }
    @Override
    public void render(){
        if(manager.update()){
            }

    }
    private void load(){

        manager.load("enemytest.pack", TextureAtlas.class);
        manager.finishLoading();
    }
}

这是GameScreen类..

public class GameScreen implements Screen{

    private GameStage stage;
    public Texture bg;

    public GameScreen() {
        stage = new GameStage();
    }
    @Override
    public void render(float delta) {
         //Clear the screen

        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                //Update the stage
        stage.act(delta);
        stage.draw();

    }

这是我想从AssetManager获取TextureAtlas图像的地方。

public class Enemy extends GameActor{

    private Animation animation;
    private float stateTime;
    AssetManager manager = new AssetManager();
    public Enemy(Body body) {
        super(body);
        TextureAtlas textureAtlas = manager.get("enemytest.pack", TextureAtlas.class);
        TextureRegion[] animationFrames = new TextureRegion[getUserData().getTextureRegions().length];

1 个答案:

答案 0 :(得分:1)

实际上,

我找到了解决方案。

我发现使用assetmanager是不必要的。滞后问题是由于

为TextureAtlas和Animation使用1024px x 1024px图像。

我不得不降低它的分辨率..发现使用TextureAtlas,findRegion和Animation

毕竟效率很低。

通过assetmanager单独加载图片似乎是更好的动画解决方案。

当我说到这一点时,我会发布另一个答案。