0

Use libGDX platform. After loading textures my application gets short and not controlled freeze.

    @Override
public void render() {
    float deltaTime = Gdx.graphics.getDeltaTime();

    if (IS_LOG_ENGINE_SPEED_INFO) {
        startTickCount = System.currentTimeMillis();
        runingAppTime += deltaTime;
    }
    if (sceneDirector.sceneUpdate()) {
        deltaTime = 0;
        if (!manager.update()) {
            Gdx.app.log("aaa", "Skip!");
            return;
        }
    }
    sceneDirector.getCurScene().updateLogic(deltaTime);
    if (IS_LOG_ENGINE_SPEED_INFO) {
        logStr = (System.currentTimeMillis() - startTickCount) + ", ";
        startTickCount = System.currentTimeMillis();
    }

    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    batch.setProjectionMatrix(camera.combined);

    sceneDirector.getCurScene().updateGraph(batch);

    if (IS_LOG_ENGINE_SPEED_INFO) Gdx.app.log("aaa", logStr + (System.currentTimeMillis() - startTickCount));
}

What I do: If changed the scene - workout the method sceneDirector.sceneUpdate () and there is a loading of textures. Texture loading function:

    public static void loadAtlas(String pngFileName, String xmlFileName, Scene scene) {

    MainClass.manager.load(pngFileName, Texture.class);
    MainClass.manager.finishLoading();
    Texture texture = MainClass.manager.get(pngFileName, Texture.class);
    scene.textures.add(texture);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    ...

And what do we get in the end... Loading methods work out correctly. Rendering graphics is only when the texture loading. This is confirmed by the logs that show the application:

01-07 16:38:50.509: INFO/aaa(27259): LogicTime: 1712, GraphTime: 145
01-07 16:38:50.559: INFO/aaa(27259): LogicTime: 0, GraphTime: 38
01-07 16:38:50.559: INFO/aaa(27259): LogicTime: 0, GraphTime: 1
01-07 16:38:50.569: INFO/aaa(27259): LogicTime: 0, GraphTime: 3
01-07 16:38:50.579: INFO/aaa(27259): LogicTime: 1, GraphTime: 1
01-07 16:38:50.589: INFO/aaa(27259): LogicTime: 0, GraphTime: 1
01-07 16:38:50.609: INFO/aaa(27259): LogicTime: 2, GraphTime: 2
01-07 16:38:50.629: INFO/aaa(27259): LogicTime: 0, GraphTime: 1
01-07 16:38:50.649: INFO/aaa(27259): LogicTime: 0, GraphTime: 4

But! Why first and second graphics update do so long? This question is important because after loading the graphics immediately begin action on the scene.

4

1 回答 1

0

这个:

MainClass.manager.finishLoading();

可能是您的时间去向(尽管我不确定,因为您没有显示MainClass.manager定义,也没有显示从renderto的调用图loadAtlas)。您需要在后台加载资产(请参阅 参考资料manager.update())。 finishLoading将阻塞当前线程(渲染线程),直到加载所有资产。

这意味着您需要在加载资源之前在渲染线程上“渲染”。通常,这是通过显示“加载”屏幕来完成的。看到这个问题:如何使用 libgdx 资产管理器正确加载纹理

于 2013-01-07T17:41:57.487 回答