[ ]




Brian - July 1st, 2010 - Scalable Art Via Manifests

In a lot of code - my code even - you see statements like this a lot:

DrawImage(x, y, image.width, image.height)

Basically, draw the whole image. This seems like a perfectly harmless statement, but it doesn't scale. The problem portion is that we're keying off the image's size.

"But Brian," I hear you start as I look upon your pouty face, "I want to draw the whole image. What else would I do?"

The answer is that you'd still specify the asset's source rectangle ala some manifest file and keep that file up to date.

"But Brian," you continue, that ugly expression still present, "That's extra work for no perceptible gain."

And here's where I talk to you about the perceptible gain:
Things go wrong. One day you're going to run out of memory or you're going to want to port the game to some other platform. You'll find that your images really need to be square powers of 2 for your texture compression to work (stupid PowerVR), and so you add some padding only to find that your previous code does not support the change. You'll find that you need to pack a lot of little images into one big image to help with compression or load times or texture thrashing or whatever, and so you do that only to find your previous code does not support the change. You'll find that you want to move to a platform that doesn't support large images and so you have to break up your big images into smaller ones, and so you do that only... you get the point. Now you're faced with a lot of extra work and a lot of potential bugs.

"But Brian," you're really irritating at this point, and I just want to slap you, "an extra file means another place to forget things and add errors."

That's reasonable but not terribly burdensome. If you need to add files to the manifest before you ever see them in-game, then when you forget to add a file you'll spot it almost immediately (assuming you test like a good engineer). If it's really too much for you, there are certainly ways to auto-generate the manifest depending on how you do texture packing/padding.

My next post will be on PowerVR and why it sucks.

Entering Apple Bashing mode...

2 Responses to “Scalable Art Via Manifests”

  1. Andrew Says:

    Call me a novice by all means, so please edjumicait me. Can you do percentages vs using direct pixel to pixel ratios then align the screen size accordingly? Break it up into sections then so as to allow porting to other devices?

  2. Brian Says:

    That’s fine for destinations (usually) but not for source rectangles, which this post was focusing on. Using percentages for source images doesn’t help when the image has to be padded or otherwise adjusted - any percentages will be wrong after the image changes size.

    Also using percentages & alignment cues & auto-layout schemes helps with porting to similar devices, but when you change form factors entirely (ala going from the iPhone to the iPad), you’ll often want to redesign UI elements to fit the new device. Having a data-driven setup goes a long way to doing this smoothly. I’ve touched on that in previous posts but not this one.

Leave a Comment

Spam Protection by WP-SpamFree