Game Development Reference
In-Depth Information
Now, the cycle starts over by handling (new) system events once again. Another
system event that can occur during runtime is the exit event. When it occurs, LibGDX
will first change to the pause() state, which is a very good place to save any data that
would be lost otherwise, after the application is terminated. Subsequently, LibGDX
changes to the dispose() state where an application should do its final cleanup to
free all the resources that it is still using.
This is also almost true for Android, except that pause() is an intermediate state
that is not directly followed by the dispose() state at first. Be aware that this event
might occur anytime during an application runtime when the user has pressed the
Home button or if there is an incoming phone call in the meanwhile. In fact, as long
as the Android operating system does not need the occupied memory of the paused
application, its state will not be changed to dispose() . Moreover, it is possible that
a paused application might receive a resume system event, which in this case would
change its state to resume() , and it would eventually arrive at the system event
handler again.
Starter classes
A starter class defines the entry point (starting point) of a LibGDX application.
It is specifically written for a certain platform. Usually, these kinds of classes are
very simple and mostly consist of not more than a few lines of code to set certain
parameters that apply to the corresponding platform. Think of them as a kind of
bootup sequence for each platform. Once booting is finished, the LibGDX framework
hands over control from the starter class (for example, the demo-desktop project) to
your shared application code (for example, the demo / demo-core project) by calling
different methods from the ApplicationListener interface that the MyDemo class
implements. Remember that the MyDemo class is where the shared application
code begins.
We will now take a look at each of the starter classes that were generated during
the project setup.
Running the demo application on a desktop
The starter class for the desktop application is called Main.java . The following
listing is Main.java from the demo-desktop project:
package com.packtpub.libgdx.demo;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
public class Main {
 
Search WWH ::




Custom Search