A Gradle Primer for Libgdx Users

Every time I set up a new project I learn something about how Gradle works and the default project setup for Libgdx. I’ve decided to write this down to save myself time the next time I start a project. I’m using Intellij IDE from what I read things are different in Eclipse. If using Intellij it is important to note that a Gradle run configurations targeting a sub-project run task  can be used in lieu of an application run configuration. The advantage of doing this is that asset location and jvm arguments are all handled in Gradle files making project set up easier for multiple users.

Most start with Gradle sites say you should start by installing gradle. Good news is Libgdx uses Gradle Wrapper, which provides scripts for both Linux and Windows allowing Gradle to be run without installing. Yay!

The next thing most starting with Gradle tutorials will say is ‘create a hello world task’ and this is where we’re going to diverge a bit since files and tasks were created during project set up. So I’m going to discuss the various Gradle files the Libgdx project setup program created.

The Files


gradle.properties

  • Not totally sure what this does, but it appears to be arguments for when Gradle gets launched by the wrapper.

settings.gradle

  • This is a short file indicating the structure of the project. It indicates how the various sub-projects are organized. The basic setup just lists ‘core’ + all of the target platforms.

build.gradle

  • There are a number of build.gradle files; one in the main folder and one in each of the platform folders. Having multiple build.gradle files the standard format for Gradle projects with subprojects.
  • The build.gradle file in the main folder contains dependencies for both external libraries and the internal subprojects. This is where the platform subprojects are related to the core subproject and the libgdx and other library dependencies are managed.
  • The build.gradle files in the subproject folder contain build tasks associated with each of the projects. For example the desktop subproject has a run task that can be used to launch the desktop application.

Now let’s look at modifying things.

If we want to add a runtime argument to indicate the location of a log4j2 configuration file we would add the line

“jvmArgs = [‘-Dlog4j.configurationFile=log4j2.xml’]”

To the top of the run task.

 

If a client-server project is desired where the platform and core projects become sub projects of the client project this can be done by prepending ‘client:’ to the existing project names in the settings.gradle file and the main build.gradle file. This assumes that both the platform and core sub-projects are contained in the client folder as shown below.

Bot Escape Demo released

Hey Look A Thing!

You can download the demo release here.

About the Game

What do you in Bot Escape? Drive around a robot and look for a door. How do you do it? glad you asked.

  1. Use a controller! One of the purposes of this project was to learn how to get controller input and that works.
  2. Keyboard Controls (keyboard controls can be changed under options)

‘a’ left

‘d’ right

‘w’ jump

‘e’ shoot missile

Here’s some screen shots

Even More About The Game

Generally don’t expect too much. This project originated as a way to learn about box2D, controller input, Wang tiles, and maze generating algorithms. I think there’s some potential to be a decent game if some good levels are designed. I tried my hand at designing two levels and have come to the conclusion that level design is hard and I’m not currently in the mood to do it. So who knows when we’ll get real levels for Bot Escape. In the mean time try out the maze and let me know what you think of the controls.

Known issues

Sometimes the robot catches on horizontal surfaces in the generated mazes. This is an artifact of box2D, jump to unstick the robot.