2

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?

Wingjam
  • 742
  • 8
  • 17
  • 1
    What exactly do you want to happen after pressing the pause button? You say you want to pause the libgdx lifecycle. How are you planning to resume it afterwards? – noone Jul 28 '15 at 16:27
  • When I press the pause button, I want to pause everything in Libgdx and I want to display a pause menu with a play button. I am planning to resume the lifecycle when the user close the pause menu by clicking on the play button. – Wingjam Jul 28 '15 at 17:06
  • 1
    You cannot display anything, when the libgdx lifecycle is completely stopped. Just set a `paused` variable, check that in your `render()` method and skip all gameplay stuff in case it's paused. Also display your pause menu. – noone Jul 28 '15 at 17:20
  • 2
    Yeah, I think you're getting thrown by the word pause being used as the name of a lifecycle event. You don't want to mess with that. Create your own type of pause that changes what's happening in the render loop, like @noone said. – Tenfour04 Jul 28 '15 at 17:22

1 Answers1

1

If your goal is to stop the render:

To stop the render:

Gdx.graphics.setContinuousRendering(false);

To put it back on:

Gdx.graphics.setContinuousRendering(true);

To trigger render when the rendering is stop:

Gdx.graphics.requestRendering();

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

Hope it will help you.

Marc Bourque
  • 82
  • 10