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.


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.

  • \$\begingroup\$ Great, I love this approach. Many thanks for sharing. \$\endgroup\$ – VictorB Jan 24 '14 at 9:39

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


  • 1
    \$\begingroup\$ Yes, thanks. But this is what I do at the moment. I was wondering though whether there's a more general approach than simply checking the ApplicationType each time I need platform specific code. \$\endgroup\$ – VictorB Jan 23 '14 at 12:44
  • 1
    \$\begingroup\$ @VictorB you could abstract your classes out into implementations that will be called for each platform \$\endgroup\$ – wes Jan 23 '14 at 12:51
  • \$\begingroup\$ Thanks. I had a similar idea too. Given that platform specific code is required in a fair number of screens, both for rendering and input processing (for example making use of the accelerometer on Android as opposed to keyboard on Desktop), I was wondering whether there is a specific approach, even design pattern, if you will, that people use in their practices that I could adopt too. Otherwise I could waste time trying things not worth trying and I don't exactly want that. If there is no such thing, then I will have to conform and do things my way. \$\endgroup\$ – VictorB Jan 23 '14 at 12:57
  • 1
    \$\begingroup\$ @VictorB rolling your own would surely be your best bet. Depending on how complex you're wanting to get, you could put the values for each platform into a configuration file with a lookup based on the application type and grab each set of values when you need them (similar to how people do multi-language applications -- that might be a good area to research. Instead of languages, you'd be using platforms) \$\endgroup\$ – wes Jan 23 '14 at 13:01
  • \$\begingroup\$ Thanks. That's a good idea which I'll have to check out. \$\endgroup\$ – VictorB Jan 23 '14 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.