0
votes

I originally implemented loading TextureAtlas directly from the asset folder but the game got really laggy as I had to call each region of the TextureAtlas for frames to be used in animation (libgdx stated that using findregion for TextureAtlas is SLOW=lag). So I decided to use assetloader to minimize the lag but the problem is I can't find a way to load TextureAtlas (.pack) via AssetManager. I am keep getting the

com.badlogic.gdx.utils.GdxRunTimeException: Assets not loaded: enemytest.pack

I kept trying using other loaders as well but it didn't go well..I could not find any resources so I need help :( Thanks you in advance!

In my assets folder, I have "enemytest.png" and "enemytest.pack" files.

This is a Game Class (extends Game)

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();
    }
}

This is GameScreen class..

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();

    }

This is where I want to get the TextureAtlas image from the AssetManager.

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

1 Answers

1
votes

Actually,

I found the solution.

I found that using assetmanager is unneccessary. The problem of lagging was due to

using 1024px x 1024px images for TextureAtlas and Animation.

I had to lower the resolution of it.. Found out that using TextureAtlas,findRegion, and Animation

is very inefficient after all.

Loading images separately via assetmanager seems to be better solution for animation.

I will post another answer when I get to the point.