Search code examples
buttonlibgdx

Close button event in libgdx


How to override libgdx window "X" button method?

For example I want to add dialog: "Are you sure you want to close app?" with two buttons "Yes" and "No" to confirm the choice.


Solution

  • If your game implements ApplicationListener (most I´ve seen do this), when you press the "X" button, dispose() gets called.

    You can create your dialog on the dispose() function.

    Edit: Little note, if your main game class extends Game (LibGDX Class), you can use this method, Game implements ApplicationListener.