Game Development Reference
In-Depth Information
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new
LwjglApplicationConfiguration();
cfg.title = "demo";
cfg.width = 480;
cfg.height = 320;
new LwjglApplication(new MyDemo(), cfg);
}
}
In the preceding code listing, you can see the
Main
class: a plain Java class without
the need to implement an interface or inherit from another class. Instead, a new
instance of the
LwjglApplication
class is created. This class provides a couple
of overloaded constructors to choose from. Here, we pass a new instance of the
MyDemo
class as the first argument to the constructor. Optionally, an instance of
the
LwjglApplicationConfiguration
class can be passed as the second argument.
The configuration class allows you to set every parameter that is configurable for
a LibGDX desktop application. In this case, the window title is set to
demo
, and the
window's width and height is set to
480
by
320
pixels.
This is all you need to write and configure a starter class for a desktop project.
Let's try to run the application now. To do this, right-click on the
demo-desktop
project in
Project Explorer
in Eclipse and then select the
Java Application
option
from the
Run As
menu. Eclipse might ask you to select the
Main
class when you
do this for the first time. Simply select the
Main
class, and also check whether the
correct package name (
com.packtpub.libgdx.demo
) is displayed next to it, as
shown in the following screenshot: