Android Game Development with libGDX

I had initially started development using Android and OpenGL ES using straightforward Java. But quickly ran into responsiveness issues due to naive use of Collections and the automatic garbage collector. After reading around the subject I stumbled onto libGDX (as mentioned in the previous post) and decided to start afresh. The library as a whole I found to be very straightforward to use. Great tools for setting up the initial projects. Excellent and expansive documentation for the API and cookbooks for actually making use of the library in your own application.

The result is a 2D game inspired by the arcade games played in my youth – The likes of Space Invaders, Silkworm and Missile Command to name a few.

PlanetKillers In-Game A

PlanetKillers In-Game Screenshot


The general concept is a sort of steampunk or more Wellsian-era battle of primitive weaponry versus vastly superior technology. “Bows and arrows against the lightning!”. You are in control of a train (Class A4 inspired) racing across the country whilst using the artillery cannon to shoot the aliens before they bomb you or make it to the other side of the screen.


All of the graphics and sprites were drawn using InkScape – a free vector graphics package. Although they were loaded into the game as PNGs (with alpha). This gives some future proofing for devices with much greater resolution screens. Ideally there would be a nice way to render SVG images directly in-game.


The libGDX setup tools produce everything you need to get started provided you have already installed the Eclipse IDE (with the ADT plugins and Android SDKs). The tutorials again are top-notch. The game can be executed as a desktop application, an Android application, a browser application or if you have suitable tools as an iOS application.

The resultant game is quite snappy, although there are still areas that can be better optimised (to make better use of the libGDX library) and optimise the graphics to be device resolution-specific.

The AI might also be a little too hard too soon for some lesser-skilled players. See how you get on.

Android app on Google Play

Android Game Development

I have been wanting to get back into developing simple arcade games for the last few years. With modern mobile devices packing some serious processing power it seemed like a good time to start again. Back then it was all C++ and desktop Windows PCs using OpenGL or DirectX (or even better Irrlicht). Now, I wanted to focus on Android devices so Java and OpenGL ES were the obvious choice. To get my head back in the game (so to speak) I knocked up a simple invaders clone. The aim being to familiarise myself with OpenGL, user input options, and the performance capabilities of the devices.

I was using OpenGL ES 1.1 (fixed pipeline) and producing the meshes in code.

CubeIcosahedronSphere Approximation

Cube, Icosahedron, and sphere approximation. The Sphere is approximated by subdividing the faces of an Icosahedron and pushing out the new vertices to lie on the sphere surface. From these basic meshes we can construct some simple game objects.

Alien ShipArtillery

The scene graph makes use of transform matrices to position, scale and rotate the meshes relative to the parent node.


Each game object has a global transform applied to it, and this also applies to the bounding sphere which is used for collision detection.


The user is able to move the artillery and fire on the alien ships. When a collision is detected the ship and shell are destroyed and removed from the field of play.

This is a relatively simple scenario, and the processing capability of the mobile device should be more than sufficient to handle it. However, I noticed some slow down in the frame rate when firing (and running collision detection). The slowdown wasn’t in the physics, or the collision algorithms, but actually in the Garbage Collector being called when Collections were being modified. In the past when I’d used C++ this wasn’t an issue, memory management is handled by the user. But with Java, the Garbage Collector is an automatic process. On searching for more information about this I stumbled on this presentation by Kactus Games that gave some great insights into Android Game Development.

On further research I stumbled on an excellent framework that takes the limitations of Java into account to allow developers to create games that will run not only on Android devices, but also on the desktop, in HTML5 browsers, and on iOS devices. LibGDX is definitely worth a look. The documentation, tutorials and example code are extensive and comprehensive. I’m now going back to the start to build a quick test game using this framework prior to experimenting with some novel ideas I have for a new game.

Three Years of Electric Dawn

Three years. Thirty-two releases. Three major versions. One thousand and twelve downloads. One hundred user ratings.

I first started coding Android apps in late October 2010; three years ago. In that time, I have taken a gentle and gradual approach to developing and refining the apps, including Electric Dawn. Each autumn saw a new surge in downloads, and more constructive user feedback, leading to more improvements ready for the next autumnal wave.

Somewhere in the archives on Joel on Software I remember reading an article (many years ago) that simply stated (I’m paraphrasing here): you get more downloads/sales by improving the product than you will ever get by marketing and advertising. In the early days I did indeed dabble with online advertising (Google Ads and Facebook Ads). But the sum result was a hole in the bank balance and nothing to show for it. After that I focused solely on refining and improving the app based on feedback from some really nice customers. It’s important to remember that it takes time and effort for someone to compose an email detailing the problems they’ve had with your app, or listing out numerous ways they think it could be made better. So I’m always grateful when I receive constructive feedback, and would like to add another big Thank You! to all those who have emailed me or written constructive reviews on Google Play over the years.

As well as the many customers providing feedback, I have also been lucky to have the honest opinion of friends and family. As well as their time taken in trying out early versions. So I’d also like to add another big Thanks! for them.

I believe that I’ve reached an important milestone with Electric Dawn now, and will see how it goes over this winter before making any more changes to it.

Here’s to a winter of sunrises! 🙂

Android PWM LED

One of the improvements I’ve been wanting to add to Electric Dawn since the early days of development is to make use of the Camera LED on the device. Dawn simulators tend to have gradually brightening lights that greatly outshine the average Android screen. The closest option would be to use the Camera LED and gradually brighten this during the sunrise stage. Unfortunately, it still isn’t really feasible using the approach of Java level PWM (Pulse Width Modulation) as my tests this weekend (whilst answering a StackOverflow question) showed.

Multiple Alarms and Snooze

Improvements to Electric Dawn

Multiple Alarm Profiles

Multiple Alarm Profiles

It has been a few months in the making, but the latest version of Electric Dawn now provides the option for multiple alarm profiles and a snooze function.



To Snooze, simply tap the sunrise screen to restart the dawn simulator. Or, if the alarm is already sounding, tap the screen to delay the alarm for a few minutes. You can even change the alarm snooze duration on the preferences screen.

Android ListView and other Trials and Tribulations

So, I am currently in the midst of upgrading Electric Dawn to provide multiple alarm profiles. But the going certainly hasn’t been easy. However, I have stumbled on an excellent resource for ListViews and Adapters in Android.

Google I/O 2010 – The world of ListView by Romain Guy and Adam Powell is a fantastic resource. There are so many flawed examples of using ListView out there on StackExchange, blogs, tech sites etc. and then in complete contrast there is the definitive presentation from Google I/O 2010 that just shows you how it is supposed to be used. Brilliant!

In other news, my Samsung S3 has died completely. The symptoms look like it could be the widely written Samsung Sudden Death Syndrome. So I am now back to using my old HTC Desire (Bravo) which is now running CyanogenMod 7.2 – Android 2.3.7. It’s quite nice having a small phone again, though the limited internal memory and short battery life are still a problem.

Not too long now until the next release of Electric Dawn with added Multiple Alarm Profiles. 🙂

Sunrise Alarm

Why build a sunrise alarm clock?

I am not a winter person. Those dark wet and miserable mornings are not conducive to me leaving a comfy warm bed. The summer however is a different matter. I wake with the sunrise, and (unless I’ve been out the night before) will be awake and wanting to get up and go early. I intentionally moved to a place where the master bedroom faces East(ish) so for about half of the year I have the joy of being woken naturally. But not in the winter.

Bird Family


A few years ago I stumbled onto a website selling sunrise alarm clocks. They weren’t particularly cheap at the time, and had only basic functionality, but seemed worth trying to beat those winter blues. I bought a Sunrise System alarm clock that is similar to the current SRS 250 dawn simulator with MP3 player. It certainly improved matters, I was waking feeling less groggy than prior to using a sunrise alarm. I used this for a couple of years until I moved house and unfortunately broke the lamp in the move. I had a look at repairing it, but never did work out what was wrong. It was too expensive at that time for me to be able to afford a replacement so I went back to using a phone alarm clock. (It was summer anyway, so wasn’t too pressing an issue).

Android apps

Sometime later that summer I bought my first Android smart phone and started dabbling with Apps. Given that phones these days have sizeable screens and camera flash LEDs it seemed feasible to use them as dawn simulators. The one downside is the absolute level of brightness is considerably less than a 40W incandescent lightbulb. But when used in a darkened room (blackouts in the summer, or your average winter morning) the light from the screen was sufficient to provide the same effect of a gradual dawn.

The first versions of Electric Dawn were definitely simplistic. It was all about functionality with little in the way of aesthetic gloss. After launching on the marketplace, nature sounds were added, along with weekday selection. The newer versions of Android, along with a myriad of devices, required occasional bug fixes and feature improvements. Then last year serious effort was put into the user interface. Working with a local graphics designer, I added a better look and feel and organisation of the settings. Recently I finally added an option of a more artistic and natural sunrise effect.

Wake up gently - Electric Dawn

Wake up gently – Electric Dawn

I decided from the outset, that every improvement would be shared amongst all the original users as well as newcomers. The feedback and help from users in finding and fixing bugs has been invaluable. So I want to make sure that they get to share in the rewards of a better sunrise alarm clock. Because of this, there is only one Electric Dawn by Whimsical Otter on the market and every user is entitled to every upgrade.

Work in progress

This is a continuous work in progress. I still want to find a way to incorporate the camera LED, but as yet haven’t found any way to effectively control the brightness. It is possible to switch it on and off, but not set brightness. (Although some may comment on the possibility of PWM, from experiments so far the switching rate is currently too slow and there is an obvious flickering).

I would also like to add the option for different alarm profiles. For example being able to have one alarm profile for weekdays, and one for weekends perhaps. The design of the database for storing multiple alarm settings did take this into account even in the first version of Electric Dawn. But as a perfectionist, I would like to refactor the current codebase to clean things up before making any further serious modifications. The bolting-on of new features and patching-up of bugs and issues with new Android versions has left the codebase looking a little rough around the edges.

Of course, this doesn’t take anything away from the rigourous testing that Electric Dawn goes through before any new release. I personally use it everyday, and have done since version one, and look forward to continuing the development.

Natural Sunrise

How do you simulate a sunrise on an Android device?

This was the question on my mind since the early days of developing Electric Dawn. But it was only recently, once I had worked with a graphics designer to improve the general look and feel of the overall app, that I was ready to tackle the Natural Sunrise.

It just so happens that the standard HSV colour cylinder provides the perfect blend path for a dawn sky from 240degs to 60degs via 360degs.

The Android app uses a SurfaceView allowing us to draw directly onto the canvas and build up the image. The sky colours followed by the sun and overlayed with the organic flourish stencil. Inspiration for the organic flourish stencil came from a tutorial by InkThisScape.

I’m quite happy with the results, and enjoy watching the virtual sunrise as I wake up each morning. Hopefully, you do too! 🙂