Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过AssetManager访问Libgdx、TextureAtlas(.pack)_Java_Android_Libgdx - Fatal编程技术网

Java 通过AssetManager访问Libgdx、TextureAtlas(.pack)

Java 通过AssetManager访问Libgdx、TextureAtlas(.pack),java,android,libgdx,Java,Android,Libgdx,我最初实现了直接从资源文件夹加载TextureAtlas,但是 游戏变得非常滞后,因为我必须调用TextureAtlas的每个区域以获得动画中使用的帧(libgdx声明使用findregion作为TextureAtlas是SLOW=lag)。所以我决定使用assetloader来最小化延迟,但问题是 我找不到通过AssetManager加载TextureAtlas(.pack)的方法。我在不断地得到答案 com.badlogic.gdx.utils.GdxRunTimeException:未加载

我最初实现了直接从资源文件夹加载TextureAtlas,但是 游戏变得非常滞后,因为我必须调用TextureAtlas的每个区域以获得动画中使用的帧(libgdx声明使用findregion作为TextureAtlas是SLOW=lag)。所以我决定使用assetloader来最小化延迟,但问题是 我找不到通过AssetManager加载TextureAtlas(.pack)的方法。我在不断地得到答案

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

我也一直在尝试使用其他加载程序,但效果不佳。我找不到任何资源,因此需要帮助:( 提前谢谢你

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

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

这是游戏屏幕课程

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];
其实

我找到了解决办法

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

将1024px x 1024px图像用于纹理贴图和动画

我不得不降低它的分辨率..发现使用TextureAtlas、findRegion和动画

毕竟效率很低

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


当我说到点子上时,我将发布另一个答案。

你确定吗?重新绑定新纹理再好不过了。你似乎把异步加载过程(assetmanager)与atlas/region方法混淆了,后者将所有纹理组合在一个纹理中,只需一个openGL绑定。
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];