-
Notifications
You must be signed in to change notification settings - Fork 0
Modules overview
LibGDX comprises several modules that provide services for each step of a typical game architecture.
- Input - Provides a unified input model and handler for all platforms. Supports keyboard, touchscreen, accelerometer and mouse where available.
- Graphics* - Enables the drawing of images to the screen using the the hardware provided OpenGL ES implementation.
- Files - Abstracts file access on all platforms by providing convenient methods for read/write operations regardless of the media.
- Audio - Facilitates sound recording and playback on all platforms.
- Net - Provides methods to perform networking operations, such as simple HTTP get and post requests, and TCP server/client socket communication.
The following diagram shows the modules in a simple game architecture:
The following part briefly describes each module providing the most common use cases for each.
The Input module enables the polling of different input states on every platform. It allows polling the state of each key, touchscreen and accelerometer. On the desktop the touchscreen is replaced by the mouse while the accelerometer is not available.
It also offers the means to register input processors to use an event based input model.
The following code snippet gets the current touch coordinates if a touch (or mouse down on desktop) event is in progress:
if (Gdx.input.isTouched()) {
System.out.println("Input occurred at x=" + x + ", y=" + y);
}
In similar fashion all the supported input means can be polled and handled.
The Graphics module abstracts the communication with the GPU and provides convenience methods to obtain instances of OpenGL ES wrappers. It takes care of all the boilerplate code needed to get hold of the OpenGL instance and handles all implementations provided by the manufacturer.
Depending on the underlying hardware, the wrappers may be or may not be available.
The Graphics module also provides methods to generate Pixmaps and Textures.
For example to obtain the OpenGL API 1.0 instance, the following code will be used:
GL10 gl = Gdx.graphics.getGL10 ();
The method will return an instance that can be used to draw onto the screen. In case the hardware configuration does not support OpenGL ES v1.0, null is returned.
The following snippet clears the screen and paints it with red.
gl.glClearColor(0.1f, 0.0f, 0.0f, 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
It always returns the specific implementation of the API (lwjgl, jogl or android), so the main application doesn’t need to know specifics and will work across the whole range of platforms if supported.
The following API versions are supported:
GL Version | Method to access |
---|---|
1.0 | Gdx.graphics.getGL10(); |
1.1 | Gdx.graphics.getGL11(); |
2.0 | Gdx.graphics.getGL20(); |
To learn more about the Graphics module check its documentation here.
The Files module provides a generic way to access files regardless of the platform. It makes it easy to read and write files. File writing has some limitations, which are due to the platform security limitations.
The most common use case for the Files module, is to load game assets (textures, sound files) from the same sub-directory of the application for all platforms. It is also very useful for writing high scores or game state to files.
The following example creates a Texture from a file present in the $APP_DIR/assets/textures directory.
Texture myTexture = new Texture(Gdx.files.internal(“assets/texture/brick.png”));
This is a very powerful abstraction layer as it works on both Android and desktop.
The Audio module makes the creation and playback of audio files extremely simple. It also gives direct access to the sound hardware.
It handles two types of sound files. Music and Sound. Both types support the WAV, MP3 and OGG formats.
Sound instances are loaded into memory and can be played back any time. It is ideal for in-game sound effects that will be used multiple times, like explosions or gunshots.
Music instances on the other hand are streams from files on the disk (or SD card). Every time a file is played, it is streamed from the file to the audio device.
The following code snippet plays a the myMusicFile.mp3 sound file from the disk repeatedly with the volume half turned up:
Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/myMusicFile.mp3", FileType.Internal));
music.setVolume(0.5f);
music.play();
music.setLooping(true);
TBD
-
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)