Demos & Test Examples
Libgdx comes with a set of demo games and test examples that you can dissect and learn from:
- Metagun, a port of Markus Persson's Ludum Dare entry. A neat little 2D platformer (desktop, Android)
- Super Jumper, a basic implementation of a "Doodle Jump" like game (desktop, Android, WebGL)
- Cuboc, a Ludum Dare entry, puzzle platformer (desktop, Android, WebGL)
- Vector Pinball, a Box2D based pinball implementation kindly donated by Brian Nenninger (desktop, Android, WebGL)
- Very Angry Robots, a 2D shot em up, by Badly Drawn Rod (desktop, Android)
- Gdx Invaders, a 3D remake of Space Invaders, demonstrates how to implement renderers for both OpenGL ES 1.x and 2.0 (desktop, Android, WebGL)
- Tons of test examples that test/demonstrates how certain APIs work. These are normally used as a way to quickly debug and test things by us, but they can also serve as nice examples. Best of all, you can try them in your browser (WebGL required). Press escape to get back from a test to the test selection screen.
Setting up the demo & test sources
To get and run any of these examples we suggest the following course of action:
- Make sure you have all the prerequisits installed
- Install Ant and put its bin/ folder into your PATH environment variable. You'll need to be able to call ant from the command line.
- Get a Git client. For Windows there's Tortoise Git or the official Github app, for Linux and Mac OSX you can go with the CLI version.
- Clone the Git repository at https://github.com/libgdx/libgdx.
- Open a shell/console in the libgdx directory and enter
ant -f fetch.xml. This will pull in all native libraries from the build server. You can do this periodically to get the latest and greatest.
- Fire up Eclipse, go to File -> Import ... -> General -> Existing Projects into Workspace and select the folder of your libgdx trunk copy.
- Import all the projects you are offered to import by the import dialog (import!)
- If you get compilation errors in the android projects, don't panic! Project -> Clean ... -> Clean All Projects should do the trick. The ADT Eclipse plugin is a sturdy beast at times.
- There will be errors for the projects that use GWT. Just go to the problems view in Eclipse, right click each of them
and select quick fix. This will add the missing jar file (which we can't distribute).
Running the demo & and test apps
The test examples are contained in the gdx-tests project. This project only contains the source code. To actually start the tests on the desktop you have to run the LwjglTestStarter class, contained in the gdx-tests-lwjgl project. To run the tests on Android simply fire up the gdx-tests-android project in the emulator or on a connected device! To run the tests in your browser fire up the gdx-tests-gwt project.
Running the demo games works similarily. Each demo game has 3-4 projects, the core project, the desktop project (sometimes that's the same as the core project), the android project and the html5 project.
For both the tests and the demos the following steps are used to start the apps
- Right click one of the projects mentioned above
- Select Run As -> Java Application for desktop projects. In the upcoming dialog select LwjglTestStarter
- Select Run As -> Android Application for the android project. This will either start the emulator or deploy the test project to a connected Android device
- Select Run As -> Web Application for the html5 project. A new view opens up, click the URL that's presented to you. You might get prompted to install the GWT plugin for your browser of choice (hint: use Chrome). Note that the app
runs in development mode, which means it will be terribly slow. For full speed you have to compile the html project, then
deploy it to a web server.
For a more in-depth description of the project setup as well as how to run and debug libgdx visit this wiki article
Other Libgdx Games with Source
You can also find source code for libgdx games written by others on the web. Here's a nice selection:
- Backyards Pirates, a fun Ludum Dare entry by Stefan Wagner (desktop, Android, WebGL)
- Pax Britannica, a port to libgdx, by Stefan Wagner (desktop, Android, WebGL)
- Aureas Oceanus, another Ludum Dare entry by Stefan Wagner (desktop)
- Freegemas, a port to libgdx by David Saltares (desktop, Android)
- Frogger, by Roger Engelbert