Saturday 30 October 2010

IPHONE-ANDROID DEVELOPMENT

Which development solution?

Introduction

I decided to write this article  to help developers to choose the right solution for rapid mobile game development. This article is not to create debates between Java, Actionscript or Objective-C developers, but just to share my experience in choosing a solution for mobile game development.
My background is application enterprise and entertainment development using JEE and Flex. I’m also an author of the Apress book Beginning Java and Flex. From that you can understand that I love Java and Flex/Actionscript, but even so, my choice for the Iphone and Android game development was Corona SDK developed by Anscamobile http://anscamobile.com/
Corona is a cross platform solution that allows us to create Iphone and Android applications writing once and testing in real time using the very fast Corona simulator.
Why Corona? Below is my full story of how I lived before discovering this fantastic solution. Before choosing Corona as my mobile SDK I went trough Android, Objective-C, Cocos2d, OpenPlug, the Adobe Iphone packager and Unity3D, and I didn’t find anything better than Corona, despite my love of Java and Flex. Before moving to another language I tried, of course, to use my daily skills.
My goals
After the book I decided to spend my nights writing some games for the mobile market so before starting any development I  studied and tested the different technologies offered by the market.
Firstly, I started with Java, my preferred language, but because Apple doesn’t want to make the Java developers life easy, I started with Android.
Android
If you are a Java/Flex developer the Android learning curve is very low, and you will pick up the framework quickly. I suggest two very good books that helped me to get into Android development.
·      Hello Android
We can use Ecplise and the Eclipse Android plugin that allows us to test and debug our code within the different simulators for the different target phones. Google did an amazing job and I love it. Android is really powerful and the development is really similar to the Flex and Java one. So I felt at home. The debugging is great like normal Java development and the IDE is Eclipse. I think it is development IDE at the moment. I’m using it daily for JEE and Flex development, but thanks to its plugin architecture you can use Eclipse for many languages.
However even if I loved Android, the Android penetration is still quite small compared to the Iphone, Itouch and Ipad one so I started trying to find a solution to compile an Android application for the Iphone,  using my Java skills.
To do that I found a brilliant project called XMLVM that offers a flexible a extensible cross compiler toolchain. Using XMLVM we can cross compile from Android to Iphone and vice versa. This is a great project but after various tests I decided that this solution was more time consuming for the kind of applications that I had in my mind (2D games) and added to the slowness of the different Android simulators, the Android development was making me spend a lot of time that I didn’t have. However I still think that Android and XMLVM is a really good option.

I decided so to wait for the release of the Adobe Iphone packager (included in the  release of Flash CS5). Just before this launch Apple decided to change the rules so that  iPhone/iPad apps must be written in Objective-C, C, C++, or JavaScript. This affected directly the Iphone packager and made me and all other Actionscript and flex developers very angry. I was almost close to selling all of my apple products! But I calmed down decided to keep my Apple devices .Adobe Platform Evangelist, Lee Brimelow went on the offensive with this post. I also lost a lot of money in the stock exchange because I bet on the Adobe stock and their new CS5 release L.
I was furious, but still wanted to find the best technology to develop my games. I found a very interesting project called Openplug that is an Eclipse plugin that allows development of mobile applications in ActionScript / Flex for iPhone, Android, Symbian and other mobile phones. Flex as Java is what I do every day so I thought that this tool was what I needed. With Openplug we can write Flex/Actionscript code and it compiles then in c++ ready for the Iphone or other targets. I joined to their beta program and I think they did an amazing job. Indeed, last September Alcatel acquired them. My problem with Openplug was the limited support of many important Actionscript APIs needed for the game development. For other applications I think that it is a very good solution for all Flex developers.
Before moving to the dark side of objective-c, I gave an opportunity to Unity3D, downloading a trial version. I have some friends who have developed a very nice 3D shooting game in only 3 months. I thought that was worth consideration. I read a book and took a Unity3d online course. Even if my games are 2D games I read on a forum that Unity3D could work also for 2D games. So I thought why not learn Game Engine for all type of games instead of jumping between different technologies? It makes sense and I downloaded the Unity3D trial version.  Unity3D is a great tool for 3D games, and if in the future I create a 3D game I will probably use Unity3D because it is a really easy and really rapid development tool. Indeed, even Electronic Arts signed a long terms relationship with them. Being a geek by nature, I still prefer having everything managed by the code. But for some 3d complex games is almost impossible or really expensive develop by just writing them. For example, with Unity3D, in 2 days part time I created a player walking around a 3D world managing collisions and camera movements and importing 3D models and textures. Really amazing.  VTC offers a very nice video course about Unity3D for Iphone. I aimed to create a scrollable 2D world, but then decided  Unity is best used to develop 3D games and not 2D. It  reminds me  of Flash and Actioscript 1 when we were attaching script to MovieClips and timeline…what a mess! So I decided to give Obective-c a chance and the IOS sdk , focusing just on the Iphone/Ipad/Itouch development.
Objective-C
I started reading many books and wrote much test code, for my game, and I was very pleased with the result. The syntax is completely different from Java or Actionscript, but it is very powerful. The learning curve is not so bad, as confirmed by other developers.  There are APIs for everything and we can apply our c++ skills and write c++ code within objective-c classes. This opens up our world to all c++ libraries and frameworks, game and physics engines like the popular box2d. I have found the Objective-C development quite time consuming as I had to debug and write more code than with other languages. All objects have to be managed manually and placed in the memory using pointers, as there isn’t any garbage collection. If we forget to deallocate an object from the memory it can easily cause the crash of our application. Another bottle neck is XCode. I’m used to Eclipse and I my user experience with XCode wasn’t as nice as when I have used Eclipse. The only positive thing is the XCode Iphone simulator which is much faster than the Eclipse Android one.
On the objective-c way I found an interesting framework for building 2D games. It is called cocos2D http://cocos2d.org
Cocos2D is an Objective-C framework and provides APIs to mange the flow control between the different scenes of the game, to manage sprite sheet, effects, transitions, tile maps, and more. It’s great and very well documented. I bought from the developer the source code of his game engine implemented using cocos2d, box2d as physic engines and SVG for rendering the game world. This is really rapid development. I created my game world using the SVG editor Inkspace, and with few lines of code it worked within the game engine built on top of cocos2D.


While  testing cocos2D, checking my stocks portfolio, I saw that Adobe stock had increased by 20%. Reading the news I discovered that Apple relaxed their review guidelines allowing the Adobe Iphone packager to move forward again. Erueka! I could come back to my real nature! Actionscript!
In few days I ported my objective-c test game to Actionscript but when I tested it on the Iphone the rendering performance was terrible. Very slow.  I was using 60 FPS and all Iphone Packager documentations tips, such as setting the GPU hardware acceleration, caching all bitmaps, etc. Even optimizing the rendering produced little increase in speed. The game was unplayable.

I noticed that last 11 of October, Adobe released a new update release of the Iphone Packager but I haven’t tested it so I don’t know if the rendering problem has been fixed, but I doubt it has.

I also bought some games from the AppStore compiled with the Adobe Iphone packager but I noticed that games are suffering with the rendering even if they are doing simples tweens. What a delusion.  I understood that the Adobe iphone packager is not ready yet so I had to find another solution or come back to objective-c.
Finally the solution to all my problems came out. I found an advert for the Corona SDK based on the Lua scripting language. I had a look to the APIs and it was quite easy to learn.
I downloaded the Corona SDK game edition and I ported my game from Actionscript to Lua very easily. The rendering was perfectly smooth as was the implementation of the all game physics, collisions and animations.  With Corona and Lua we can animate a sprite sheet with just one line of code.
-- A sprite sheet with a cat
local sheet1 = sprite.newSpriteSheet( "runningcat.png", 512, 256 )
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8)
-- play 8 frames every 1000 ms
sprite.add( spriteSet1, "cat", 1, 8, 1000, 0 )
In order to activate the game physics we just have to type a few more lines of code ( 5), and then we can start introducing the various objects into our world easily. It is brilliant. Corona made my game development much faster than all the other languages that I tried and the performance is pretty amazing. There are also many examples and it is very well documented so I really recommend it.
There is also an Lua Eclipse plugin working on both Mac OS and Windows (I’m using it on Mac OS 10.6). It is not great but better than nothing.
The Corona simulator is really fast and each run is much faster that just compile a simple banner with Flash/Flex.
The debugging is a little bit more complex because is terminal based and not integrated within the Eclipse IDE, but still, the error messages are precise and this makes the debugging quite easy.
Finally the build is easy as run as a test. Just click on build instead of run and it will make the application ready to be dragged into the Itunes Apps and then copied into our Iphone.
Conclusion
I love Actioscript, and I love Java. They are my two preferred languages for enterprise applications. They are very powerful, elegant, clean, pure Objected Oriented languages. Actionscript and Flex are growing day by day and becoming very popular in enterprise applications such as banking and big multiplayer games. Adobe is making big efforts  to make  the FlashPlayer faster on all mobile phones, but regarding the Iphone pakager I don’t think they are ready yet. The performance is far lower than all the other solutions that I tested.
For the 2D games, at the time of writing, Corona SDK is a very good solution. Lua is very easy to learn and it is very powerful as well. I suggest this book, as it is a complete Lua reference.
My second choice goes to the Android + XMLVM  and Cocos2D if you want to develop just for the IOS.
For 3D games Unity3D probably is the best choice and you can leverage your Javascript and C# expertise.
For Flex developers that they don’t want do games but just mobile applications I suggest Openplug and the Iphone packager. The Iphone packager can work also for board games and other games that don’t require a lot of rendering.
Hope this post makes your life easier for whatever you like to create!

5 comments:

  1. Wow! Sounds like a long journey you've been on, but I'm glad you finally discovered Corona.

    I've been using Corona for almost exactly 14 weeks and already have 3 games published using it--it really is awesome and is great for rapid development.

    Are you on twitter? I'm @beebegames if you're interested in seeing what I've done with Corona.

    Good luck and can't wait to see what you produce with it!

    ReplyDelete
  2. Nice overview, Filippo! Which book did you recommend for Lua?

    ReplyDelete
  3. I bought just one book for now because the Corona APIs reference is quite well documented.
    Here the book that I recommend

    http://www.amazon.co.uk/Programming-Lua-Second-Roberto-Ierusalimschy/dp/8590379825/ref=sr_1_1?ie=UTF8&qid=1288656110&sr=8-1

    I'm developing a game during my nights and week-ends so I don't know when it will be finished, because after 10 hours of Flex and Java a day I'm pretty tired but I'm going definitely to finish it!!!

    ReplyDelete
  4. Really interesting post, Filippo. Very well written and informative!

    I will definitely consider what you have said, prior to starting any development work.

    ReplyDelete
  5. Hi Filippo,

    I am reading your book about flex and java... it's helping me a lot!! and it is really well written!!

    Thank you very much for it... I have also added your blog to my netvibes... I encourage you to write! we want to know what you are doing! ...and continue learning from your experience!

    Thank you again!

    Edu

    ReplyDelete