Overlap2d setup

Overlap2d is a nice little alpha project as of this writing that allows designers and developers work together to put together games leveraging libGDX, Box2d. The goal is to show how to create a new project using the libGDX wizard and then make the necessary configuration changes to the project to incorporate the Overlap2D runtimes, which are not yet available as a library dependency as of this time. Welcome to alpha land!

Some key things to notes. The following assumes that Java SDK 1.7 is installed. LibGDX libraries, and Overlap2d runtime are downloaded. If the project is going to use Android get the latest SDK. One of the first things, especially if using the latest version of libGDX there are changes to use gradle builds. These steps demonstrate LibGDX version 1.3.1. This is newer than the Overlap2d runtime project dependency at this time.

First step is to use the LibGDX project wizard gui to create your project. In the Overlap2d tutorial there is more information. For this example we will build the desktop and android subprojects.

Once libGDX project setup runs and builds the subproject folders copy the Overlap2D runtime to your project as a sub project. The folder structure looks something like this:
Project structure

The next steps are to make adjustments to the main project and sub project build.gradle files. The first build.gradle file to edit is the overlap2d-runtime-libgdx-master subproject that was just copied into the project. The change in this file is to change the dependency for libGDX to the current version of libGDX. Change the line with gdxVersion=’1.2.0′ to gdxVersion=’1.3.1’. The result change looks like this:

ext {
    gdxVersion = '1.3.1'
    box2dlightsVersion = '1.2'
    reflectasmVersion = '1.10.0'
}

Go to the main top level project folder and edit the settings.gradle file. The settings.gradle tells the gradle build to include the runtime environment. When running multiple Overlap2d dependent projects in the same eclipse workspace and each project has an Overlap2d runtime dependency this can be configured in a couple of ways. This configuration steps assumes that each project has a subproject of the overlap2d runtime in them, therefore the compile project name is different to allow eclipse to import it without saying “the project dependency already exists”.

Add to the settings.gradle, the reference name  to the overlap2d and the subproject file information and save it. The complete file looks like this:

include 'desktop', 'android', 'core','Overlap2dSideRuntime'
project(':Overlap2dSideRuntime').projectDir = new File(settingsDir, 'overlap2d-runtime-libgdx-master')

Notice that the directory name of the Overlap2d runtime is kept the same. Just the project name reference is different.

Open the build.gradle in the same top project folder. There are two sections that need to change. The android and core project references need to be changed to include some dependencies for compiling.

In the “android” project dependencies section, add the box2d dependencies needed for the Overlap2D runtime, since Overlap2D is built against box2d version 1.2. The line being added to the dependencies for the android project is:

compile “com.badlogicgames.box2dlights:box2dlights:1.2”

The android project section change result looks like this:

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.box2dlights:box2dlights:1.2"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
    }
}

The project “core” in this same file needs to also have reference to box2dlights version 1.2 and add in dependency to the Overlap2d runtime this example shows the renamed the project for compile as described in the settings.gradle mentioned above to the Overlap2d runtime subproject in the workspace:

project(":core") {
    apply plugin: "java"

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile "com.badlogicgames.box2dlights:box2dlights:1.2"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
      compile project(":Overlap2dSideRuntime")
    }
}

The final step is to import the new project into Eclipse. Make sure that eclipse has the gradle plugin. Then for the workspace select File > Import. In the import dialog, select Gradle > Gradle Project. In the “Import Gradle Project” dialog select the root folder of this project, and then click “Build Model”. This will then load the project and sub projects into the dialog. Select all the projects, and then select finish.

Eclipse Import

That should import all the projects. You can test running the desktop application and get the badlogic example, and you should be able to also build the android APK.

One thought on “Overlap2d setup

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s