Android Game Development with libGDX

androidAfter selling games on PC, Mac and Xbox 360, I want to develop games on mobile plaforms, and I will start with Android. I chose Android instead of iPhone for two reasons:

  • It’s cheaper: my Mac is a PowerPC and you need a Mac Intel for iPhone development. Also Android phones are cheaper than iPhones.
  • Java is similar to C# : I have C# games ready to be ported to mobile. As Android uses Java, it’s a great platform for me to port those games.

My last X360 game, Don’t Feed the Trolls is a great fit for mobile: quick gameplay sessions and not requiring too much processing power or memory. I therefore decided to port it to Android.

libgdxI started to look for available 2D game libraries on Android and after hesitating between AndEngine and libGDX, I chose libGDX. I will describe here some features and my thoughts about this library.

What I like

Complete API

It’s a simple but complete API. We often see libraries with only rendering support, but with libGDX, you can do rendering (2D and 3D), audio, file management and input (touchscreens). There are also a few useful utility classes and tools (more on this below).

Box2D

box2dThere is also a port of Box2D, the physics library used in Spring Up Harmony (PC, X360). If I ever want to port Spring Up Harmony to Android (probably), the physics part should be easily portable.

Open Source

I like to have access to the source code of libraries I use. I find it reassuring and when debugging, it’s good to be able to step into libraries source code.

Activity

activityThere is currently quite a lot of updates and bug fixes, by the creator of the lib (Mario Zechner) and by community.

Bitmap Fonts

font_small_cropThere is a tool available to create bitmap fonts. This is very similar to the tool I used on XNA (SpriteFont2 Texture Tool) so porting my existing code was very easy.

Desktop Version

If you ever used the Android Emulator of the SDK, you are probably aware that it’s terribly slow and not really usable. I didn’t buy my Android Device yet, but can still work on the game and test it properly because libgdx also compiles for desktop java.

Don't Feed the Trolls for Android running with the Desktop version in libGDX
Don't Feed the Trolls for Android running with the Desktop version of libGDX

Texture Packer

This is another great tool, used to pack many textures in one. I usually don’t care much about texture size and texture memory waste when developing on X360 but this is important on mobile devices due to their limitations. Some features of this tool:

  • Grouping small textures in textures pages (power of two).
  • Strip transparent pixels on the borders of textures. This required quite some tweaks and update in my own fgDrawSprite class and rendering functions to manage properly, but this is really a great way to save memory and disk space.
  • Has an incremental option to avoid generating everything when updating only some resources.
  • Can be called from the game itself in the desktop version. A good practice is to automatically call the packer in the desktop version, and use the generated assets in both Desktop and Android.

This is really a time saver tool.

What I don’t like

Lack of documentation

There is no good and centralized documentation. You need to look for information on the forums, in the source code and/or on blog articles. Due to the activity of the library, I sometimes find out that I’m using old stuff that is not supposed to be used, because it’s deprecated and has been replaced by something else. The parameters of some API functions are not always properly documented too. For instance, I had trouble using a rendering function and found out that the rotation parameter was an angle in degrees (it’s usually in radians in the libraries I used before).

Reverted Y-Axis

coordsI found this very strange but in all the 2D APIs I used, the coordinate system used the point (0,0) as the top-left corner, with X going right and Y going down. In libgdx, the Y axis is going up, and the 0,0 is bottom-left. I had to change some rendering functions to take this into account.

Android Specific

Doing Android specific code is not very clean because the lib is supposed to work on desktop and Android. I guess this is also because of Java, and I wished we could have some preprocessing to condition Android specific code. There are many workarounds, because the Android application overloads the Desktop application. So you can create empty methods on Desktop that are overloaded only in the Android project with Android specific code. I hope this won’t get too messy when I’ll work on very specific and touchy stuff such as in-app purchases.

What I don’t know

Performance

I don’t own an Android device yet and did not test other API, so I can’t really talk about the performance of the API. According to users, it is faster than most other APIs.

Conclusion

Using libGDX is a good and easy way to start developing Android games. For now, I’m happy with this library and you can see on the screenshot above that development is going well. I will probably release a few games with it.

If you tested different Android libs or have anything to add, feel free to comment about it.

You can find out more about Frozax Games or me on twitter, facebook or g+.

3 comments

  1. It really is the best toolset for game development on the Android platform at the moment, despite its somewhat patchy documentation (a bit of hunting + trial and error is needed especially with packages added recently). I found Andengine nice but it’s crippled by its reliance on debugging on the hardware – the libgdx workflow of compiling native Windows binaries then switching over to Android is magic. I’ve been detailing my experiments with it on my blog and it’s been a blast so far. The speed of having lower-level wrappers around OpenGL calls is great, even with thousands of particles on display, for instance. Only downside is its < 1.0 release state, but any bugs, missing features and lack of documentation should be filled in during the coming months.

Comments are closed.