Thursday, March 22, 2012

My very brief overview of developing for Android


Hello! Recently I was looking at developing for Android and I thought it might to helpful to share my experiences. It's a show down of Corona vs Unity vs Coco2s-x vs Adobe Air.

I had my mobile game idea and I prototyped it in Love2d in an afternoon. Love2d is a pretty good little 2d engine with a lua scripting layer. Then I wanted to port it to android add some webservices and stuff, maybe some in app transactions. My aims were / are rapid development and publishing.

I'm on a Galaxy S phone.

Corona

This is the first middleware I tried, I picked it because it was also using Lua.

The bads
  • 400ish dollars a year
  • You send your code to their servers to compile!
  • Documentation is out of date
  • The company goes down - your code is useless
  • The servers go down - you can't compile or publish
  • Debugging is poor
  • The emulator doesn't act the same actual hardware :(
  • Poor choice of memory model for Lua means really easy memory leaks. This probably due to being overly influenced by flash. 
  • (No 3d - but I don't really care about this!)
The Goods
  • Lua!
  • I ported my game in an afternoon
  • Lots of features
  • Cross platform
  • Regularly updated
  • Reasonably active community
  • Simple and easy to iterate with the emulator.
  • Easy to publish.
Why I gave up

My (very very simple) program worked fine in the emulator but after 3 play throughs of my game on the device it started to get visual artifacts.

No idea how to debug this issue and I suspect it was below my lua-code in the big scene graph that is Corona's rendering engine. I checked I had no memory leaks - which I didn't so not really sure how to solve it. I couldn't find a work around and I didn't want to waste time creating a nice error case app for the developers - I don't have the time to do it, it's a very simple program and if I'm having trouble here I know I'll have trouble with bigger projects.

Unity

At the time of testing Unity were giving out free mobile licenses so I thought - sure why not! I don't think I gave it a good shake though.

The bads
  • No easy 2d
  • Setting up a 2d scene in Unity's visual editor is tedious
  • To much exploring menus and not enough getting things done
The goods
  • It's Unity - visual editor, nice languages, massive community
  • Very visual, you can see in real time how your scene exists
I gave up after my 2d button was scaling it's width and height on the x and z axis. My canvas axis were also incorrect and I couldn't be bother to fix it by manually rotating things around. Too much setup faff. I also felt pretty confident the later stuff I'd want (in app purchases) would require an expensive license.

Coco2ds-x

Next up - a library that runs on the Android using the Native Development Kit (NDK). This a little more to the bones.

The bads
  • Eclipse, I heard it had become better in the last 10 years but it's still terrible. An IDE abomination; everyone involved with  Eclipse should feel a deep personal shame, you're actively making the world a worst place. (see this blog post from 2007 "Is it me or is Eclipse a piece of shit?" and the many comments still coming in to this day, each with their own separate horror story)
  • Cygwin, gbd, logcat, you all suck
    • I'm a games developer 80% of us, use Visual C++ don't throw us back into this 80s unix terminal world!
    • The Unix world of "Oh you want to do A? Well first you need to do B?", "Oh you want to do B? Well first you need to do C!", "Oh you want to do C? Well first you need to recompile D which won't work for your system so you'll need to do E but E requires tool G, sorry that's tool G version 1.323 you have G 1.34. Yes G can only be built from source, yes you'll need dependencies F.1 to F.6d to build it." And so on until you want to smash something. 
    • I had to root my phone because Samsung put a file in a different place than is standard
      • It was incredibly hard to find that this was the source of my problems
    • Did I mention Eclipse?
    • The common suggestion is use Linux or a virtual machine running Ubuntu. I tried Ubuntu, I tried cygwin they both but it's stepping into a entire development ecosystem I don't know (it's something I should learn though).
  • None of this is actually about Coco2ds-x yet let's start
    • Poor documentation - 5 or 6 vastly different quickstart pages linked from the wiki, none of which work
    • Many, many makefiles, script and templates and general cruft
    • The Hello World app works but the source files never seem to be in my eclipse project
    • There's a Lua project ... but printing out _G hard crashes my phone
    • It's C++ so build times suck (Actually it's worse it's a C++ with a Java bridge)
    • It's a Chinese project - which is cool but the forum support sometimes seems more like a riddle than actually help.
The goods
  • Close to the metal so easy to add extra libraries
  • Fast (probably)
  • Games have been made in it

I made a button appear on screen with the Lua project but printing out the _G would hard crash my phone and I couldn't get it to go in portrait mode. The best  I could do was get a portrait screen in the middle of landscape layout - very squashed. 

Adobe Air

This is where I am now.

The bads
  • It's Flash, so actionscript, why did you look at C++ and think "Me too"!
    • Hex values for colours? What were you thinking here? Wasn't flash aimed at non-programmers?
  • The whole touch interface doesn't really work as advertised for my phone
  • The convert mouse to touch doesn't seem to work at all for the emulator.
The goods
  • Flashdevelop is a one click install that lets you immediately develop on the phone
  • It has an emulator
  • It's easy to launch to the device (though I've yet to get remote debugging working)
  • Code complete, break points all those good modern IDE features
  • Cross platform
So it's looking like Flash is winning at the moment. Though I haven't ported in a day because I'm finding Flash a bit unfamiliar I thought it was untyped and garbage collected and maybe it was once but it seems to be one of the languages that's had a million and one things bolted on. I haven't taken the time to understand it's scene graph so I'm just kind of winging it and hoping I'm not memory leaking to hell or doing very inefficent things. 

Conclusion

Flash wins - if you want to make a game today download FlashDevelop. I'm not Flash's biggest fan but it seems the best way to do Android development. 

Secretly I think the very best way to do Android development is this 3 step process.
  1. Buy a Mac
  2. Write a game using Coco2d
  3. If the game does well, pay someone else to port it to Android.
Job done.

4 comments:

Christian said...

You should give NME a try (www.haxenme.org). I've never used it for android but it's part of the list of supported platforms. It's the ring to rule them all.

balaam said...

Thanks Christian, I'll add it to my list and give it a go!

DirtyHarry said...

Hello - thanks for the awesome website and book!

I have a question. Do you think it would be possible to write an adventure game engine running on any of the frameworks you used?

Would it be possible to implement the elements you listed in the article about Adventure Game engines components (http://www.godpatterns.com/2010/08/how-to-make-adventure-game.html) and then use a framework like Corona only for the "render" part, whereas the actual game is stored in data files - which would remain the same across all platforms - processed by the various pure Lua components?

So that if you want to switch in the future to a different engine for the rendering part, you could do it.

I am not an experienced programmer, just wanted to know your opinion on this approach.

Thanks!

balaam said...

Hi,

Yeh that's pretty possible - how much of a pain it is depends on the APIs for sound, IO (saving the game for instance) and rendering.

And of course they'd all have to use Lua as a scripting language :)