Introduction
Libgdx consists of several modules to provide services for each typical game architecture step.
- Input -Provide a unified input module for all platforms for processing. Supports keyboard, touch screen, sensor, mouse, etc.
-
- Graphics -Enable screen image rendering and support OpenGL ES.
-
- Files -Abstract all platform File Access to provide a proper method for read/write operations.
-
- Audio -Sound Recording and playback are supported on all platforms.
-
- Math -A very practical module that provides the fastest mathematical computing for Game Development
- Physics -Complete box2d Encapsulation
The following table shows the modules in a simple game architecture:
The following briefly describes the most common usage of each module.
Input
the input module polls different input states on each platform. It allows you to traverse the state of each key, touch screen, sensor, and replace touch with the mouse when the sensor cannot be used on the desktop.
indicates registering an input processing Program with an event based on the input module.
The following is a Code snippet. If a touch event occurs while the program is running, obtain the current touch coordinate
If(GDX. Input. istouched ()){
System. Out. println ("Input occurred at x =" +X+ ", Y =" +Y );
}
All similar functions that support input are traversed and processed.
Graphics
The graphics module abstracts the communication between GPUs and instances that provide appropriate methods to obtain OpenGL ES. He processes all the sample code, keeps OpenGL instances and processes all the implementations provided by the manufacturer.
The graphic module provides methods to generate bitmap and texture. For example, you can use the following code to obtain an example of OpenGL API 1.0.
Gl10 GL=GDX. Graphics. getgl10 ();
The above method returns an instance object that can be drawn on the screen. If the hardware configuration does not support OpenGL ES V1.0, null is returned. The following snippet clears the screen with a red brush
Gl. glclearcolor (0.1f,0.0f,0.0f,1);
Gl. glclear (gl10.gl _ color_buffer_bit );
It returns a specific API instance (lwjgl, jogl or Android). Therefore, you must manually specify the APIS supported by the main application.
Supported API versions
1.0 |
GDX. Graphics. getgl10 (); |
1.1 |
GDX. Graphics. getgl11 (); |
2.0 |
GDX. Graphics. getgl20 (); |
To learn more about the graphic module, click Here
Files
The file module provides a generic method to access files without having to worry about the platform. It is easy to read and write files, and file writing has certain limitations, because of the security restrictions of the platform.
The most common usage of a file module is to load a game resource from a subdirectory of the same application. It is useful for writing the highest score or game status files
The following example creates a texture file from the current $ app_dir/assets/textures directory.
Texture mytexture= NewTexture (GDX. Files. Internal ("Assets/Texture/Brick.png "));
This is a very powerful abstraction layer used to work between Android and desktop applications.
Audio
The audio module makes it easy to create and play an audio file. He can also directly access the sound hardware. It processes two types of audio files. Music and sound ). Supports WAV, MP3, and Ogg formats.
Each time a file is played, it will flow out of the audio device.
The following code snippet plays oneMymusicfileworkflowSound and set the volume to half
Music=GDX. Audio. newmusic (GDX. Files. getfilehandle ("Data/mymusicfile.pdf", Filetype. Internal ));
Music. setvolume (0.5f);
Music. Play ();
Music. setlooping (True);
Math
TBD (not officially available)
Physics
TBD (not officially available)