Pages

Friday, November 16, 2012

The Friday Project - Update 5


Scene2d UI is great for GUIs

I admit it. I may have misjudged scene2d UI in the past. In fact, I definitely misjudged it. I thought it was overkill and overcomplicated, and it always seemed to be in a state of flux. And in general my GUI needs are usually little more than a couple of buttons, so historically I have rolled my own GUI code.

But something made me take another look at scene2d UI last week, and I'm rather glad that I did because in its latest incarnation it is really rather good.

Today, thanks to scene2d UI, I...

  • ripped out my old score display code in the playing screen's GUI and replaced it with scene2d UI code
  • added a pause button to the playing screen's GUI
  • added a pause overlay that is displayed when the game is paused
  • went to lunch with my wife
  • dozed off in my chair after lunch, then fixed the scaling so that the game didn't look too stretched on screens with a 3:2 aspect ratio
It was adding the pause overlay that brought it home just how good scene2d UI actually is. All it took to make the pause overlay appear on top of the playing screen's GUI was to use a Stack. When the overlay is needed, it is created and put on top of the stack. When it is no longer needed, it is removed. And that's it. No messing around with state, no keeping track of special cases, because it's already done for you. Simple and effective.

Scaling

Back when Android devices first came out, there wasn't much need to worry about scaling. There were very few resolutions and very few device sizes. That made it relatively easy to adjust to different resolutions and aspect ratios, as there wasn't all that much to do. But now, there are tiny QVGA screens (320 x 240) all the way up to 10 inch tablets, such as the glorious looking Nexus 10 with its 2560 x 1600, high pixel density screen. I dread to think what Very Angry Robots looks like on one of those because I know that its code made a number of assumptions that are no longer true.

Fortunately that's not going to be a problem with Whirling Frenzy because I've thought about it carefully. It's designed to run with a 16:9 aspect ratio (eg, 1280 x 720). On screens with a different aspect ratio it will "letterbox" to keep things from looking stretched, but rather than leaving black bars it will draw a little more of the level. In theory that would give owners of phones with a 3:2 aspect ratio a small advantage in that they'll see a little more vertically, but in practice the difference isn't really visible.

Now all I have to do is get hold of a Nexus 10 to test it on.

This week's snapshot

Here's this week's playable snapshot. The game is much the same, but the GUI is beginning to improve. Click this link or scan the QR code to download it to your Android device.

No comments:

Post a Comment