{"id":816,"date":"2011-09-27T21:52:00","date_gmt":"2011-09-27T19:52:00","guid":{"rendered":"http:\/\/www.frozax.com\/blog\/?p=816"},"modified":"2015-04-04T19:49:42","modified_gmt":"2015-04-04T19:49:42","slug":"android-game-development-libgdx","status":"publish","type":"post","link":"https:\/\/www.frozax.com\/blog\/2011\/09\/android-game-development-libgdx\/","title":{"rendered":"Android Game Development with libGDX"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-841  alignright\" title=\"android\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/android_small.png\" alt=\"android\" width=\"72\" height=\"84\" \/>After selling games on <a href=\"http:\/\/www.frozax.com\/pc_games.php\">PC<\/a>, <a href=\"http:\/\/www.frozax.com\/mac_games.php\">Mac<\/a> and <a href=\"http:\/\/www.frozax.com\/x360\">Xbox 360<\/a>, I want to develop games on mobile plaforms, and I will start with Android. I chose Android instead of iPhone for two reasons:<\/p>\n<ul>\n<li>It&#8217;s cheaper: my Mac is a PowerPC and you need a Mac Intel for iPhone development. Also Android phones are cheaper than iPhones.<\/li>\n<li>Java is similar to C# : I have C# games ready to be ported to mobile. As Android uses Java, it&#8217;s a great platform for me to port those games.<\/li>\n<\/ul>\n<p>My last X360 game, <a href=\"http:\/\/www.frozax.com\/games\/dont-feed-the-trolls\">Don&#8217;t Feed the Trolls<\/a> 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.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-full wp-image-844\" title=\"libgdx\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/libgdx.png\" alt=\"libgdx\" width=\"235\" height=\"51\" \/>I started to look for available 2D game libraries on Android and after hesitating between <a href=\"http:\/\/www.andengine.org\/\">AndEngine<\/a> and <a href=\"http:\/\/code.google.com\/p\/libgdx\/\">libGDX<\/a>, I chose libGDX. I will describe here some features and my thoughts about this library.<\/p>\n<h2>What I like<\/h2>\n<h3>Complete API<\/h3>\n<p>It&#8217;s a <a href=\"http:\/\/libgdx.l33tlabs.org\/docs\/api\/overview-summary.html\">simple but complete API<\/a>. 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).<\/p>\n<h3>Box2D<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-full wp-image-869\" title=\"box2d\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/box2d.gif\" alt=\"box2d\" width=\"86\" height=\"76\" \/>There is also a port of <a href=\"http:\/\/www.box2d.org\">Box2D<\/a>, the physics library used in\u00a0<a href=\"http:\/\/www.frozax.com\/games\/spring-up-harmony\">Spring Up Harmony (PC, X360)<\/a>.\u00a0If I ever want to port Spring Up Harmony to Android (probably), the physics part should be easily portable.<\/p>\n<h3>Open Source<\/h3>\n<p>I like to have access to the source code of libraries I use. I find it reassuring and when debugging, it&#8217;s good to be able to step into libraries source code.<\/p>\n<h3>Activity<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-full wp-image-854\" title=\"activity\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/activity.png\" alt=\"activity\" width=\"106\" height=\"20\" \/>There is currently quite <a href=\"http:\/\/www.ohloh.net\/p\/libgdx\">a lot of updates<\/a> and bug fixes, by the creator of the lib (<a href=\"http:\/\/www.badlogicgames.com\/wordpress\/?page_id=2\">Mario Zechner<\/a>) and by community.<\/p>\n<h3>Bitmap Fonts<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-full wp-image-857\" title=\"font_small_crop\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/font_small_crop.png\" alt=\"font_small_crop\" width=\"82\" height=\"53\" \/>There is a tool available to create bitmap fonts. This is very similar to the tool I used on XNA (<a href=\"http:\/\/www.nubik.com\/SpriteFont\/\">SpriteFont2 Texture Tool<\/a>) so porting my existing code was very easy.<\/p>\n<h3>Desktop Version<\/h3>\n<p>If you ever used the <a href=\"http:\/\/developer.android.com\/guide\/developing\/tools\/emulator.html\">Android Emulator<\/a> of the SDK, you are probably aware that it&#8217;s terribly slow and not really usable. I didn&#8217;t buy my Android Device yet, but can still work on the game and test it properly because libgdx also compiles for desktop java.<\/p>\n<figure id=\"attachment_848\" aria-describedby=\"caption-attachment-848\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/dftt_android.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-848\" title=\"Don't Feed the Trolls for Android running with the Desktop version in libGDX\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/dftt_android-300x188.png\" alt=\"Don't Feed the Trolls for Android running with the Desktop version in libGDX\" width=\"300\" height=\"188\" \/><\/a><figcaption id=\"caption-attachment-848\" class=\"wp-caption-text\">Don&#39;t Feed the Trolls for Android running with the Desktop version of libGDX<\/figcaption><\/figure>\n<h3>Texture Packer<\/h3>\n<p>This is another great tool, used to pack many textures in one. I usually don&#8217;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:<\/p>\n<ul>\n<li>Grouping small textures in textures pages (power of two).<\/li>\n<li>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.<\/li>\n<li>Has an incremental option to avoid generating everything when updating only some resources.<\/li>\n<li>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.<\/li>\n<\/ul>\n<p>This is really a time saver tool.<\/p>\n<h2>What I don&#8217;t like<\/h2>\n<h3>Lack of documentation<\/h3>\n<p>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&#8217;m using old stuff that is not supposed to be used, because it&#8217;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 <em>rotation <\/em>parameter was an angle in degrees (it&#8217;s usually in radians in the libraries I used before).<\/p>\n<h3>Reverted Y-Axis<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-full wp-image-863\" title=\"coords\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/09\/coords.png\" alt=\"coords\" width=\"108\" height=\"99\" \/>I 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.<\/p>\n<h3>Android Specific<\/h3>\n<p>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&#8217;t get too messy when I&#8217;ll work on very specific and touchy stuff such as <a href=\"http:\/\/developer.android.com\/guide\/market\/billing\/billing_overview.html\">in-app purchases<\/a>.<\/p>\n<h2>What I don&#8217;t know<\/h2>\n<h3>Performance<\/h3>\n<p>I don&#8217;t own an Android device yet and did not test other API, so I can&#8217;t really talk about the performance of the API. According to users, it is faster than most other APIs.<\/p>\n<h2>Conclusion<\/h2>\n<p>Using libGDX is a good and easy way to start developing Android games. For now, I&#8217;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.<\/p>\n<p>If you tested different Android libs or have anything to add, feel free to comment about it.<\/p>\n<p>You can find out more about Frozax Games or me on <a href=\"http:\/\/twitter.com\/frozax\">twitter<\/a>, <a href=\"http:\/\/www.facebook.com\/frozax\">facebook<\/a> or <a href=\"http:\/\/plus.google.com\/115825125240096966280\">g+<\/a>.<\/p>\n<div class=\"addtoany_share_save_container addtoany_content_bottom\"><div class=\"a2a_kit a2a_kit_size_32 addtoany_list a2a_target\" id=\"wpa2a_1\"><a class=\"a2a_button_twitter\" href=\"http:\/\/www.addtoany.com\/add_to\/twitter?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F09%2Fandroid-game-development-libgdx%2F&amp;linkname=Android%20Game%20Development%20with%20libGDX\" title=\"Twitter\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_facebook\" href=\"http:\/\/www.addtoany.com\/add_to\/facebook?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F09%2Fandroid-game-development-libgdx%2F&amp;linkname=Android%20Game%20Development%20with%20libGDX\" title=\"Facebook\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_google_plus\" href=\"http:\/\/www.addtoany.com\/add_to\/google_plus?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F09%2Fandroid-game-development-libgdx%2F&amp;linkname=Android%20Game%20Development%20with%20libGDX\" title=\"Google+\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_reddit\" href=\"http:\/\/www.addtoany.com\/add_to\/reddit?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F09%2Fandroid-game-development-libgdx%2F&amp;linkname=Android%20Game%20Development%20with%20libGDX\" title=\"Reddit\" rel=\"nofollow\" target=\"_blank\"><\/a>\n<script type=\"text\/javascript\"><!--\nwpa2a.script_load();\n\/\/--><\/script>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>After 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&#8217;s cheaper: my Mac is a PowerPC and you need a Mac Intel for iPhone development. Also Android phones are cheaper than iPhones.&hellip; <a class=\"more-link\" href=\"https:\/\/www.frozax.com\/blog\/2011\/09\/android-game-development-libgdx\/\">Continue reading <span class=\"screen-reader-text\">Android Game Development with libGDX<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,3,12],"tags":[55,90,109,114],"_links":{"self":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/816"}],"collection":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/comments?post=816"}],"version-history":[{"count":1,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/816\/revisions"}],"predecessor-version":[{"id":1685,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/816\/revisions\/1685"}],"wp:attachment":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/media?parent=816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/categories?post=816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/tags?post=816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}