代码之家  ›  专栏  ›  技术社区  ›  Wingjam

如何从Libgdx动态调用重写暂停方法?

  •  2
  • Wingjam  · 技术社区  · 9 年前

    我创建了一个Libgdx游戏,我想知道是否可以使用Libgdx调用覆盖暂停方法生命周期?

    下面是我的类中的暂停方法生命周期:

    public class MyGdxGame extends ApplicationAdapter {
        @Override
        public void pause() {
            super.pause();
            chrono.pause();
            //Display a pause menu
        }
    }
    

    我想在单击暂停图像时调用生命周期方法:

        imagePause = new Image(new Texture(Gdx.files.internal("pause.png")));
        imagePause.setSize(pauseSize, pauseSize);
        imagePause.setPosition(width - pauseSize, height - pauseSize);
        imagePause.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                //Something like this? :
                Gdx.app.pause(); //Doesn't exist
    
                //I don't want to call manually the pause method like this       
                //because it doesn't pause Libgdx lifecycle ...
                pause();
            }
        });
        stage.addActor(imagePause);
    

    知道吗?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Marc Bourque    9 年前

    如果您的 球门 是为了 停止 这个 提供 :

    要停止渲染,请执行以下操作:

    Gdx.graphics.setContinuousRendering(false);
    

    要重新打开:

    Gdx.graphics.setContinuousRendering(true);
    

    要在渲染停止时触发渲染,请执行以下操作:

    Gdx.graphics.requestRendering();
    

    文档: https://github.com/libgdx/libgdx/wiki/Continuous-&-non-continuous-rendering

    希望它对你有所帮助。