Game Development Reference
In-Depth Information
Querying the platform type
You might want to write a platform-specific code where it is necessary to know
the current platform type. The following example shows how it can be done:
switch (Gdx.app.getType()) {
case Desktop:
// Code for Desktop application
break;
case Android:
// Code for Android application
break;
case WebGL:
// Code for WebGL application
break;
case iOS:
// Code for IOS application
break;
default:
// Unhandled (new?) platform application
break;
}
Querying the memory usage
You can query the system to find out its current memory footprint of your
application. This might help you find excessive memory allocations that could
lead to application crashes. The following functions return the amount of memory
(in bytes) that is in use by the corresponding heap:
long memUsageJavaHeap = Gdx.app.getJavaHeap();
long memUsageNativeHeap = Gdx.app.getNativeHeap();
Multithreading
When our game is created, LibGDX creates a separate thread called the Main
loop thread and OpenGL context is attached to it. The entire event processing or
rendering happens within this thread and not in the UI thread. Hence to pass data
to the rendering thread from another thread, we use Application.postRunnable() .
This will run the code in the Runnable function in the rendering thread in the next
frame, as shown in the following code:
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
 
Search WWH ::




Custom Search