Book Image

Mastering LibGDX Game Development

By : Patrick Hoey
Book Image

Mastering LibGDX Game Development

By: Patrick Hoey

Overview of this book

Table of Contents (18 chapters)
Mastering LibGDX Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding the high-level component layout of LibGDX


We are now going to review the architecture behind LibGDX. As a quick note, the latest stable release of LibGDX that we are going to use throughout this book is version 1.5.5, which was built on 19 March, 2015.

LibGDX backend modules

The following figure (Figure 4) is a diagram illustrating the core interfaces of LibGDX. These are the highest level abstractions available that provide most of the functionality you will need when creating your game (including their associated module libraries):

Figure 4

These interfaces are implemented for each of the currently supported target platforms, allowing you to develop your game once, using these APIs and not having to worry about platform-specific issues. An overview of the functionality that each interface contains (once implemented for each supporting platform) is as follows:

  • Application.java: This interface becomes the entry point that the platform OS uses to load your game. Each implementation will be responsible for setting up a window, handling resize events, rendering to the surfaces, and managing the application during its lifetime. Specifically, Application.java will provide the modules for dealing with graphics, audio, input and file I/O handling, as well as logging facilities, memory footprint information, and hooks for extension libraries.

  • Graphics.java: This interface contains numerous helper methods for communicating with the platform's graphics processor, such as rendering to the screen and querying for available display modes such as graphics resolution and color depth. There are also convenience methods for generating pixmaps and textures. One interesting note is that for cross-platform support, the underlying graphics API (OpenGL ES 2.0 or OpenGL ES 3.0) is emulated for the desktop by mapping OpenGL ES functions to the desktop OpenGL functions.

  • Audio.java: This interface contains numerous helper methods for creating and managing various audio resources. This interface helps to create sound effects, play music streams, and give direct access to the audio hardware for PCM audio input and output.

  • Files.java: This interface contains numerous helper methods for accessing the platform's filesystem when managing game assets such as reading and writing files. This abstraction over the different types of file locations includes internal files (located in your game working directory) and external files (external storage such as an SD card).

  • Input.java: This interface contains numerous helper methods to poll (or process events) for user input from not only standard input such as keyboard key presses and mouse button clicks, but also mobile device input such as touch screens and accelerometer updates. Other helper methods include handling vibrations, compass access, on-screen keyboard input, and cursor capture.

  • Net.java: This interface contains numerous helper methods for performing certain network-related operations, such as managing HTTP/HTTPS GET and POST requests and creating TCP server/client socket connections.

  • Preferences.java: This interface contains numerous helper methods for storing and accessing application game setting values as a lightweight setting storage mechanism.

LibGDX core modules

The rest of the functionality that you will use for your game belongs to a host of core modules within the LibGDX framework:

Figure 5

The modules in the left column (audio, files, graphics, input, and net) in Figure 5 were already discussed previously in Figure 4. The other modules are as follows:

  • Maps: This module contains classes for dealing with different level map implementations, such as maps generated from Tiled (an XML-based format called TMX) and Tide. The convenience methods include handling the loading of the map and referenced assets, rendering the map, accessing properties, and selecting different layers.

  • Math: This module contains classes with convenient utility methods for dealing with various mathematical calculations such as trigonometry, linear algebra, and probability. These methods are also optimized to be fast. Other classes include geometric classes for dealing with shapes, areas, and volumes, collision detection tests such as intersection and overlap, and interpolation algorithms.

  • Assets: This module contains classes for managing the loading and storing of assets such as textures, bitmap fonts, particle effects, pixmaps, UI skins, tile maps, sounds, and music. These classes will also deal with different caching strategies to optimize the storage and use of your game assets.

  • Scenes: This module contains classes for building 2D scene graphs used in creating UIs such as game menus and HUD overlays. This module also provides classes for managing the laying out, drawing, and handling input for the different UIs.

  • Utils: This module is more of a catchall for various miscellaneous pieces of utility methods that don't quite fit anywhere else. This module supports reading and writing in XML and JSON (with serialization support), custom collections with primitive type support (which helps to avoid performance hits when autoboxing types), timers, and object pools.

There are other libraries that come with LibGDX, but typically maintained by third parties. These will fall under the extensions folder. The LibGDX extensions folder includes the following:

  • gdx-box2d: This is a physics engine for 2D rigid bodies

  • gdx-bullet: This is a real-time physics simulation library

  • gdx-controllers: This is for gamepad and joystick controller support

  • gdx-freetype: This generates bitmap fonts on the fly from one TrueType font (TTF) file

  • gdx-jnigen: This allows C/C++ code to be written inline with Java source code

  • gdx-setup: This is the UI project setup application used to manage LibGDX installs with the Gradle build system

  • gdx-tools: This is a miscellaneous collection of tools to aid in the development of your game, such as a particle effect editor, a texture packer application, and a bitmap font creator utility