1
\$\begingroup\$

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.

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

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.

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

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

https://stackoverflow.com/a/15891372/1620568

Application.ApplicationType will return one of the following results:

  • Android
  • Applet
  • Desktop
  • iOS
  • WebGL

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Application.html#getType%28%29

\$\endgroup\$
5
  • 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
    Commented Jan 23, 2014 at 12:44
  • 1
    \$\begingroup\$ @VictorB you could abstract your classes out into implementations that will be called for each platform \$\endgroup\$
    – wes
    Commented Jan 23, 2014 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
    Commented Jan 23, 2014 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
    Commented Jan 23, 2014 at 13:01
  • \$\begingroup\$ Thanks. That's a good idea which I'll have to check out. \$\endgroup\$
    – VictorB
    Commented Jan 23, 2014 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .