Code Samples

On this page we have provided several samples illustrating various technical challenges in game development. These samples include many examples that are commonly requested in this course. All of these samples come with source code. You are allowed to use the code here as reference or directly in your own games.

This page has all of the demos that we will show in lecture throughout the semester. You are encouraged to look at them ahead of time to give you a jump start on your project. We find that these demos cover most of the major issues that you might run into when developing your game.

With that said, we are always looking for more demos. If you discover something cool that is not here, let us know. We are more than willing to add more demos for students to look at.

Ship Demo

This example demonstrates image drawing, rotation and scaling, and background drawing from an image. It also has sound effects and simple mathematics for physics. This is the code from the first programming lab.


This example shows how to use JSON to define your level format. Modifying the json file allows you to change the level without recompiling the demo; just hit start.

Parallax Scrolling

This example shows off parallax scrolling to give your game some feeling of depth. Parallax scrolling does not actually give you 3D game play, but it does make the game look nicer.

Texture Mapping

This example shows you how to do sophisticated texture mapping, beyond what is done in the basic SpriteBatch class. This required us to make an alternative class to SpriteBatch classed VertexBatch. The application itself is simple and displays a single textured polygon. Press = or - to change the number of vertices on the polygon, and press T to then texture on or off. You can distort the polygon by clicking on a vertex and dragging it.

Memory Pool

This example shows how to use free lists to keep control over your allocations. Free lists are supported by the Pool class in LibGDX. These are particularly useful for particle systems.

box2d Physics

This example shows off how to use the Box2D physics engine for movement and collision. It is much simpler than Lab 4 because there are no joints involved. This shows the bare minimum that you can do with the engine. Use the number keys 0-9 to change the various settings in the demo.

box2d Lights

This example shows off how to use Box2d to make a top-down game with simple lighting effects. It requires an additional library called Box2DLights, which was an option when you set up your game. Like the JSON Demo, this example defines the level layout with JSON files, allowing you to reset the lights on the fly. There are multiple light settings in this demo. Use the keys P and N to page through them all.


With the proliferation of Java versions, we have discovered in recent years that these samples are not always turn-key. Sometimes issues with your Java environment may force you to rebuild them from scratch.

In that case, you will need to make a new project. Make sure to set the package to be the same as the original project (e.g. edu.cornell.gdiac.shipdemo). Uncheck all subprojects other than Desktop. For extensions choose Freetype, Controllers, and Box2d. In one obvious case, you should add Box2dlights as well.

Once you have done that, copy the directories core/assets, core/src and desktop/src into your new project. Edit the configurations and run the new project.