One way to make extra income if you are a developer is to start creating games for the Android OS. In the past, this could prove difficult on the Android, because you either had to buy an expensive tool such as Unity or you needed to write in OpenGL which is downright painful. BadLogic’s gdx library makes it much easier to get started writing games. It provides a simple architecture along with some helpful classes for quickly getting together a simple 2d game. The gdx library is open source and is also written in such a way as to allow you to use the same source code for multiple platforms including the desktop, ios, and even html. The open source community is constantly updating the library and building in richer and versatile features.
Setting up the Environment for Android Studio
This will probably prove the most challenging for getting started, but once you’ve got the basic template for gdx setup, you’ll be ready to go. The easiest way to create a gdx setup, is to run the gdx-setup.jar file which creates a gradle ready project that can be imported into Android Studio. Simply download the gdx-setup from the link above , launch the command prompt from the pc (type cmd) and run the following line:
java -jar <directory you downloaded the gdx-setup>/gdx-setup.jar
This will Launch a java GUI project generator, that will allow you to generate your project.
You’ll need to browse for where your android sdk is. You can figure out the path by going into Android studio, and going to the menuTools -> Android -> SDK Manager. Once you launch the manager, it will display the path for all the SDKs. While you are in the SDK Manager, you may want to make sure you have upgraded to the 19.1 tools, because its required for the gdx-setup.jar to build properly.
You can uncheck iOS, Html, and Desktop if you are only planning on building an Android project. Leave Box2D checked, because this may be useful for you in writing your Android game.
When you are ready, click generate and wait for the project to be created.
Bringing the Project into Android Studio
Once the gdx-setup is finished running, you can import the build.gradle file into Android Studio. Go to File -> Import in the Android Studio menu, and browse for the build.gradle under your project directory that you set in destination when you ran the gdx-setup generator.
Click Okay, and Android Studio will precede to bring in the project using gradle and download everything it needs. Once its finished, your android directory structure will looking something like the figure below:
Building and Running
You can build the application from the Build -> Make Project menu item inside of Android Studio. It may take a while, but once its finished you are ready to run on your Android. Hook a USB up to your Android device. You’ll have needed to setup up your Android device settings to allow for Debugging through a USB. You’ll also need to have installed all the required drivers through the SDK Manager. If all is well, when you run the android project, you’ll see the screen turn red, and a sample image called badlogic.jpg show up in the bottom left hand corner of your device.
GDX Lib is a free versatile java library for creating device independent games. In order to use it in the Android Studio environment, you should use gdx-setup to generate what you need for your game project framework. In the next article we’ll get into how to move actors around the screen using the gdx library and begin our journey into our first game.