Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine which platform the current app is running on in LibGDX?

I need to offer slightly different app logic depending on the deployment platform my LibGDX app is running on, i.e. Desktop or Android, etc., does the LibGDX API offer a method of identifying the current runtime platform?

This post, "abstracting platform specific code in libGDX" offers a solution of sorts, I'm just wondering if there is something directly available in the API itself (?).

like image 845
Big Rich Avatar asked Apr 09 '13 00:04

Big Rich


2 Answers

You could potentially use Application#getType(), which will return one of the values defined by Application.ApplicationType:

  • Android
  • Applet
  • Desktop
  • iOS
  • WebGL
like image 114
MH. Avatar answered Oct 09 '22 19:10

MH.


If people are having trouble figuring out where you actually get the ApplicationType from, it's accessed from:

Gdx.app.getType()

And for a working example this would do:

if(Gdx.app.getType() == ApplicationType.iOS) {
    //Do awesome stuff for iOS here
}
like image 20
Nine Magics Avatar answered Oct 09 '22 18:10

Nine Magics