LibGDX资产依赖性降低进度

时间:2019-03-21 18:13:27

标签: kotlin libgdx

更多的是关于框架本身(特别是 AssetManager )的一般问题,而不是关于代码的问题。

当我注意到游戏加载状态中的进度条在某个时候下降百分比时,我一直在开发自定义加载器,以缓存我的纹理地图集的轮廓效果。是我的加载器,需要加载依赖项:基本图集和着色器(以及用于深度纹理的另一个图集)。

我的装载机通常看起来像这样(在Kotlin中):

class OutlineLoader(
    resolver: FileHandleResolver
) : AsynchronousAssetLoader<OutlineAtlas, OutlineLoader.Parameter>(resolver) {
    override fun loadSync(manager: AssetManager, name: String, 
                          file: FileHandle, params: Parameter): OutlineAtlas {
        val sourceAtlas = assetManager.get<TextureAtlas>(name)
        val depthAtlas = assetManager.get<TextureAtlas>(params.depth)
        val shader = assetManager.get<ShaderProgram>(params.shader)

        return OutlineAtlas(sourceAtlas, depthAtlas, shader)
    }

    override fun getDependencies(name: String, file: FileHandle, 
                                 params: Parameter) =
            Array<AssetDescriptor<*>>().also { array ->
                listOf(
                        AssetDescriptor(name, TextureAtlas::class.java),
                        AssetDescriptor(params.depth, TextureAtlas::class.java),
                        AssetDescriptor(params.shader, ShaderProgram::class.java)
                ).forEach(array::add)
            }


    ...
}

因此,我正在排队一些资产,以后再使用它们。 AssetManager的Logger输出确认。然而,进展达到25%,然后达到20%;增至60%,然后增至33%。我插入了debug-print语句,以查看每次assetManager.update()调用后的加载进度,就像这样:

[AssetManager] Queued: sprites/sprites.atlas, foo.bar.OutlineAtlas
[AssetManager] Loading: sprites/sprites.atlas, foo.bar.OutlineAtlas
[DEBUG] Loading: 0%
[AssetManager] Loading dependency: sprites/sprites.atlas, com.badlogic.gdx.graphics.g2d.TextureAtlas
[AssetManager] Loading dependency: sprites/depth.atlas, com.badlogic.gdx.graphics.g2d.TextureAtlas
[AssetManager] Loading dependency: shader/depth.frag, com.badlogic.gdx.graphics.glutils.ShaderProgram
[DEBUG] Loading: 0%
[AssetManager] Loaded: 20.16505ms shader/depth.frag, com.badlogic.gdx.graphics.glutils.ShaderProgram
[DEBUG] Loading: 25%
[AssetManager] Loading dependency: sprites/depth.png, com.badlogic.gdx.graphics.Texture
[DEBUG] Loading: 20%
[AssetManager] Loaded: 20.56412ms sprites/depth.png, com.badlogic.gdx.graphics.Texture
[DEBUG] Loading: 40%
[AssetManager] Loaded: 85.70349ms sprites/depth.atlas, com.badlogic.gdx.graphics.g2d.TextureAtlas
[DEBUG] Loading: 60%
[AssetManager] Loading dependency: sprites/sprites.png, com.badlogic.gdx.graphics.Texture
[AssetManager] Loading dependency: sprites/sprites2.png, com.badlogic.gdx.graphics.Texture
[AssetManager] Loading dependency: sprites/sprites3.png, com.badlogic.gdx.graphics.Texture
[AssetManager] Loading dependency: sprites/sprites4.png, com.badlogic.gdx.graphics.Texture
[DEBUG] Loading: 33%
[AssetManager] Loaded: 72.27248ms sprites/sprites4.png, com.badlogic.gdx.graphics.Texture
[DEBUG] Loading: 44%
[AssetManager] Loaded: 116.72272ms sprites/sprites3.png, com.badlogic.gdx.graphics.Texture
[DEBUG] Loading: 56%
[AssetManager] Loaded: 165.29959ms sprites/sprites2.png, com.badlogic.gdx.graphics.Texture
[DEBUG] Loading: 67%
[AssetManager] Loaded: 237.17233ms sprites/sprites.png, com.badlogic.gdx.graphics.Texture
[DEBUG] Loading: 78%
[AssetManager] Loaded: 341.5768ms sprites/sprites.atlas, com.badlogic.gdx.graphics.g2d.TextureAtlas
[DEBUG] Loading: 89%
[AssetManager] Loaded: 405.7238ms sprites/sprites.atlas, foo.bar.OutlineAtlas

在搜索源中,我不知道这是故意的还是我盲目地做一些愚蠢的事情? (我也没有在Wiki中找到有关该主题的内容。)

编辑:调试打印语句看起来像这样:

if (!assetManager.update()) {
    val progress = "${assetManager.progress * 100f}%"
    Gdx.app.debug("[DEBUG]", progress)
} else { ... }

在Java中只是AssetManager.getProgress()

0 个答案:

没有答案