How to call the override pause method dynamically from Libgdx?

时间:2015-07-28 15:44:21

标签: java libgdx override lifecycle onpause

I create a Libgdx game and I want to know if it is possible to call the override pause method lifecycle with Libgdx?

Here is my pause method lifecycle in my class:

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

And I want to call the lifecycle method when I click on the pause image:

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

Any idea?

1 个答案:

答案 0 :(得分:0)

如果目标停止 呈现

停止渲染:

Gdx.graphics.setContinuousRendering(false);

重新开始:

Gdx.graphics.setContinuousRendering(true);

在渲染停止时触发渲染:

Gdx.graphics.requestRendering();

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

希望它会对你有所帮助。