How do I show a Quit button on Desktop but don't show it on Android with libgdx?

| | August 18, 2015

So I would like to display a Quit button on the Desktop main menu screen, but I wouldn’t want to have it on Android too. What is the correct approach to achieve this? Do I have to check the ApplicationType of the app each time I want to display something different on the two platforms, or is there a more general approach maybe?

The same question is valid for text for example.
Say, on Desktop it should say “Click to continue” whilst on Android – “Tap to continue”.

To mention that both projects (Desktop and Android) share the same main project, since they have been created using the gdx-setup-ui tool.

Thank you.

2 Responses to “How do I show a Quit button on Desktop but don't show it on Android with libgdx?”

  1. Another thought:

    You pass a resource provider to the constructor of your ApplicationListener, and get your string values (or other resources) from it.

    You wind up with one abstract class in the core project for the resources that do not change, and a derived class in each of the platform projects for the resources that do change.

    In this way, you only do this at the start of the app, and the rest of the game is completely oblivious to the difference, which is what I think you are looking for.

  2. To add in platform specific code, you may check the application type with libgdx.

    Application.ApplicationType will return one of the following results:

    • Android
    • Applet
    • Desktop
    • iOS
    • WebGL

Leave a Reply