Game Development Reference
In-Depth Information
The demo application - time for code
In this section, we will take a closer look at the actual code of the demo project.
Thereafter, we will do some simple modifications to the code and also use
the debugger.
Inspecting an example code of the demo
application
Let's take a first look at the generated code of MyDemo.java from the demo project.
The following code snippet shows the class definition:
public class MyDemo implements ApplicationListener {
// ...
}
As you can see, the MyDemo class implements the ApplicationListener interface.
The MyDemo class from Gradle project ( demo-core ) produces a quite different code
as follows:
public class MyDemo extends ApplicationAdapter {
//...
}
Here, the ApplicationAdapter is an abstract class that implements the
ApplicationListener interface. Before we move on to the implementation details
of the interface, we will spend some time on the remaining part of this class.
You will find a definition of the four member variables, each with a class provided
by LibGDX:
Private OrthographicCamera camera;
Private SpriteBatch batch;
private Texture texture;
private Sprite sprite;
Here is a brief explanation of the classes from the preceding code listing to give you
the basic background knowledge for the code inspection that will follow shortly.
The camera variable is of the class type OrthographicCamera . We will use the
orthographic camera to display our 2D scenes. The camera is the player's view
of the actual scene in the game, which is defined by a certain width and height
(also called viewport).
 
Search WWH ::




Custom Search