Text layout with GlyphLayout and ScreenViewport in libGDX

I want to post some code (and screenshots!) for laying out text on screen with libGDX. libGDX changed the way it handles text recently, so I wanted to write new code to accommodate, and I also wanted to make the layout work relative to the bounds of a Viewport. GUI code can get to be a hassle real fast, so to keep it simple, there’s just three options for horizontal layout (left, center, right), and three for vertical layout (bottom, middle, top). Here’s the code: Continue reading →

Alternatives to Object-Oriented Programming

I wrote another post on the team blog, this time about moving away from OOP. I go over a couple of the problems I have with OOP, specifically modelling after real-world objects, and the isolation of objects. And, what’s more useful, I briefly introduce alternative approaches, with links to the most helpful articles and talks that I have found. Alternative approaches include Component-Entity-System, Data-Oriented Programming, and Semantic Compression. Check it out!


Installing nVidia Drivers on LMDE

The Why

I’m running Linux Mint Debian Edition (LMDE), and I needed to install the nvidia drivers in order to develop WebGL applications. Without the nvidia drivers, the display was a little laggy, but fast enough. Not being able to run WebGL, however, was kind of a show stopper.

So I did a bunch of research. There’s a lot of information out there, and only some of it is contradictory, but it’s all confusing. Everything seemed tailored for either Linux Mint or Debian, not LMDE. And there are also a lot of warnings about systems that don’t boot after rejecting the new drivers. All of this lead to a few hours of hand-wringing before I took the plunge.

Turns out it’s really easy. Continue reading →

Et tu, Enum?

Hidden Memory Allocations

I’ve worked hard to keep memory allocations out of the main loop of the game I’m working on. All the game entities, the components, the event and messaging systems, all those data structures get recycled. The pooling system in LibGDX has been a big help, but there’s still a lot of bookkeeping logic to cover to make it work correctly.

So today I finally got a chance to see how well I’d done by running the code on an actual device with DDMS watching allocations. I started tracking allocations, played through, and this is what I got:
Continue reading →

In which I set up Android Build Tools to run on a 64-bit System without Multiarch

The problem

I was creating a build server for an Android project on a remote web host run by Webfaction, but I was running into a problem when running the ant scripts. I had installed the Android SDK in my home directory according to these instructions, but running ant clean debug threw this error:

I checked, and /home/stevehb/bin/android-sdk-linux/build-tools/20.0.0/aapt existed. I couldn’t see a reason that ant couldn’t find it, so I eventually tried to run it myself.
Continue reading →

Installing the Android SDK on a Headless Server

If you want to set up a remote build machine for an Android project, one of the first obstacles you’ll encounter is how to install the SDK from the command line. Both the SDK installer and AVD Manager are designed to be run graphically. Fortunately, there are some options for command line setups.

First thing you’ll need to do is download the SDK tools. You probably just need the SDK Tools tgz file for a linux install. You do not need the ADT Eclipse plugin, nor the ADT bundle. Those all need a GUI.

Then, after unpacking that file, you’ll need to set up the environment variables and install the actual platform SDKs. There are SDKs for the different APIs you can target (ie, API 15, API 19, etc), so you’ll need to know what you’re aiming at. Google has some old information about how to install those SDKs on a headless machine, but here are all the steps themselves, as well as some caveats.
Continue reading →

Loading IntMaps from JSON with libGDX

libGDX comes with a JSON serializer/deserializer that let’s you move data between JSON files and your Java data structures with just a few lines of code. This works mostly automatically, even with more complex data hierarchies.

We’ll start with an example of how this works, then how it breaks when reading an IntMap, and finally how to fix it.

For the working example, let’s take this class:

And this JSON:

Then you can deserialize the JSON to an ObjectMap with

Boom! Done. You can focus on data structures and data, and not worry about how to move them back and forth. Unless you try to pull the same trick with an IntMap…
Continue reading →