Early version of Android support!

I’ve been meaning to get things up and running on Android devices for a while. My friend Rudi loaned me his Nexus 7 tablet for the weekend (thanks bro!), so I figured it was time to get proper Android support going!

This actually turned out to be fairly simple. We already had support for loading assets at 1x, 2x, 4x depending on device resolution. So it was just a matter of creating a new “platform type” of ANDROID, turning on Starling.handleLostContext (required for Android apps), and doing a few calculations to figure out what size of assets we should use. It’s not perfect yet – eventually I’d like to do further adjustments based on the dpi, whether or not it’s a tablet, etc.

					var serverString:String = unescape(Capabilities.serverString);
					var reportedDpi:Number = Number(serverString.split("&DP=", 2)[1]);
					var isTablet:Boolean = DeviceCapabilities.isTablet(stage);
					var divisor:Number = 1;
					var isRetina:Boolean = false;
					if (reportedDpi <= 120) // ldpi
					{
						divisor = 1;
					}
					else if (reportedDpi <= 160) // mdpi
					{
						divisor = 1;
					}
					else if (reportedDpi <= 240) // hdpi
					{
						divisor = 2;
					}
					else // xdpi
					{
						divisor = 4;
						isRetina = true;
					}

					Constants.DEVICE_DEF = new DefDevice(DeviceType.ANDROID, divisor, 
						"Android_Device", largestResValue, largestResValue / divisor, 
						smallestResValue / divisor, isTablet, isRetina);

This gets us most of the way there. It certainly lets the game start up at any Android resolution, load some assets, and display correctly at most of the common resolutions. Unfortunately it’s never that simple though…there are many Android resolutions that cause headaches due to aspect ratios that are vastly different from those encountered on iOS (which is all we’ve cared about up to this point). A few places were pretty easy to fix, simply scaling images where necessary, doing a bit smarter positioning of some UI elements, etc. But our in-battle view is still a bit of an issue at many different resolutions.

samsung_galaxy_s_battle_problems

Samsung Galaxy S – 800×480…that doesn’t look quite right!

The fix for issues like the one in the picture above is not terribly difficult, it’s just tedious. I haven’t fixed it yet, I’m going to spend my time focusing on getting the game done and ready for release on iOS first, then will make the necessary adjustments to make everything look good at all resolutions.

To fix the above problem, a good start would be to divide the screen roughly in half vertically. Then scale the background tiles (that have the torches, bricks, windows, etc. on them) to fit vertically. The top UI elements (health bar, progress bar, etc.) are okay since they’re positioned relative to the top and sides of the screen. Whatever value we scale the background by will have to be applied to Grimm and all monsters. To fix the bottom half, we can start by scaling the background image to fit vertically. Then we can look at scaling the tiles and tileboard. Finally we’ll need to figure out how much room we have for all of our buttons, and attempt to scale them to a decent size, and then position them relative to the sides of the screen and the tileboard. Again, not difficult, just takes time.

In any case, I’m feeling confident about everything. All iOS devices are now working, and things are looking pretty nice on a Nexus 7 as well:

device_farm

Clockwise from left – iPad 2, iPhone 5, iPhone 3 GS, Android Nexus 7 2012 (1280×800) – my little “Device Farm” 🙂

For now, it’s back to tearing through the rest of my (now much smaller) task list!

Leave a Reply

Your email address will not be published. Required fields are marked *