-
Notifications
You must be signed in to change notification settings - Fork 0
The application framework
At its core, libgdx consists of five interfaces that provide means to interact with the operating system. Each back-end implements these interfaces.
- Application: runs the application and informs an API client about application level events, such as window resizing. Provides logging facilities and querying methods for e.g. memory usage.
- Files: exposes the underlying file system(s) of the platform. Provides an abstraction over different types of file locations on top of a custom file handle system (which does not inter-operate with Java's File class).
- Input: informs the API client of user input such as mouse, keyboard, touch or accelerometer events. Both polling and event driven processing are supported.
- *Net**: provides means to access resources via HTTP/HTTPs in a cross-platform way, as well as create TCP server and client sockets.
- Audio: provides means to playback sound effects and streaming music as well as directly accessing audio devices for PCM audio input/output.
- Graphics: exposes OpenGL ES 1.x and 2.0 (where available) and allows querying/setting video modes and similar things.
The only platform specific code that needs to be written, are so called starter classes. For each platform that is targeted, a piece of code will instantiate a concrete implementation of the Application interface, provided by the back-end for the platform. For the desktop this might look something like this, using the Lwjgl back-end:
public class DesktopStarter {
public static void main(String[] argv) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new MyGame(), config);
}
}
For Android, the corresponding starter class might look like this:
public class AndroidStarter extends AndroidApplication {
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGame(), config);
}
}
These two classes usually live in separate projects, e.g. a desktop and an Android project. The Project Setup, Running & Debugging page describes the layout of these projects for Eclipse.
The actual code of the application is located in a class that implements the ApplicationListener interface (MyGame in the above example). An instance of this class is passed to the respective initialization methods of each back-end's Application implementation (see above). The application will then call into the methods of the ApplicationListener at appropriate times (see The Life-Cycle).
See Starter Classes & Configuration for details on starter classes.
== Accessing Modules == The modules described earlier can be accessed via static fields of the Gdx class. This is essentially a set of global variables that allows easy access to any module of libgdx. While generally viewed as very bad coding practice, we decided for using this mechanism to ease the pain usually associated with passing around references to things that are used often, at all kinds of places within the code base.
To access e.g. the audio module one can simply write the following:
// creates a new AudioDevice to which 16-bit PCM samples can be written
AudioDevice audioDevice = Gdx.audio.newAudioDevice(44100, false);
Gdx.audio
is a reference to the backend implementation that has been instantiated on application startup by the Application instance. Other modules are accessed in the same fashion, e.g. Gdx.app
to get the Application, Gdx.files
to access the Files implementation and so on.
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Gradle Project Setup, Running, Debugging and Packaging
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * 2D Animation * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * Viewports * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics * Quick Start * Models * Material and environment * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- Deploying your Application
- Building Libgdx ??
- Known Issues
- Articles
- Deprecated (May be outdated)