Scaling actors

In a point and click adventure game there are many rooms in which the actor’s distance to the ‘camera’ is more or less the same everywhere he goes.
But there might be rooms where perspective is important. Think long hallways, large outside areas, huge room, weird camera angles, etc.
Look at the picture below. These are a few examples of area’s where the actor can move closer to and further away from the camera:

scalingexamples

When you play these games (Day of the Tentacle, Indiana Jones and the Fate of Atlantis, and Monkey Island II) these areas feel very natural. How the actor scales and moves depending on the location feels just right (most of the time).

What is it that it feels natural? And how do you implement this?First thing you notice when you walk around these areas is that the actors scales down or up depending on how ‘far away’ the character is. Its size matches the surroundings where he walks.
But scaling alone is not enough. You also have to adjust the vertical and horizontal walking speed. If you don’t adjust that speed, and the actor is half its normal size because it’s far away, then the speed in which he walks seems ridiculous fast.

So when implementing this adapting behavior, you have to adjust 3 variables: size of the actor, horizontal speed, and vertical speed. It is necessary to adjust both vertical and horizontal speed, because depending on the room, you need different walking speeds in different areas. These values might be different from room to room, especially when your game has a very cartoonish style with weird deformations and perspectives (like Day of the Tentacle).

Implementation
Allright, let’s implement this. How do we know what size and speed the actor needs? How can we define this in our room?
There are several ways to accomplish this. Probably more than the 3 I’ll mention here:

1. Scaling using the Y axis
Using this method you just scale the actor down when it goes up on the screen. In many rooms this is sufficient. When the character walks into the distance, most of the time it is also going up on the screen. This is the easiest implementation. Just add a scale factor to the Y position on the screen. And also scale the vertical and horizontal movement speed.
Pros: Very easy to implement. Probably sufficient for most rooms.
Cons: It limits the type of rooms you can create, because you can’t create a room with different scaling factors on the same y-axis.

2. Scaling using walkboxes
This can only be used when you use walkboxes, or polygons to define the walkable area. If you build a walkable area using walkboxes/polygons, you can add a scale factor to each vertex of the walkbox/polygon and interpolate that scale factor depending on the position the actor is inside that walkbox/polygon. With this you can create a very exact scaling (depending on how detailed your walkable area is), but it can be very time consuming to adjust all the scale factors on all the vertices.
Pros: Easy to implement. It allows for many different styles of rooms.
Cons: Time consuming to edit and maintain

3. Use alpha value for scale factor
This is the method we use for now and it suits our needs. For this method we create an extra bitmap image for each room that needs actor scaling. That bitmap is only painted in the walkable area. The transparency (alpha value) of each pixel defines the scale factor used. So when the actor is walking around we know exactly on which pixel he is in the bitmap (the bitmap is obviously not shown. It’s only loaded in memory). So we can scale the actor and its movement according to the alpha value of the pixel.
Using tools like Adobe Photoshop it is easy to create a gradient bitmap where the transparency gradually increases.
Pros: Very easy to implement. It allows for many different styles of rooms.
Cons: Not necessarily easy to create for everyone

Example
Let’s look at a simple example created using our own engine:
(disclaimer: crappy programmer art and a stolen character sprite)

Here we see a room with a deep hallway and some stairs. The actor scales down when he walks down the hallway further away from the ‘camera’. He scales up when he gets closer. When he walks up the stairs, he only scales down a little bit (barely¬†noticeable).

Using method 1, scaling on the y-axis, would not work here, because our character would scale down a huge amount when walking up the stairs.
In our engine we use method 3. That means we have a bitmap for the background, and another bitmap for the scaling using transparency. This can be seen here:

And combined with the background:

You can see the transparency increases down the hallway. And it increases only a little going up the stairs.

Our engine loads this bitmap in memory when the room is loaded. When the actor walks around the room, the engine knows on which position it walks on the background bitmap, so it also know which pixel to pick from the bitmap in memory. Then we use ‘alpha value’ of that pixel to determine the scale factor.

Which scale factor you need depends on the room, and it’s a lot of trial and error to get it just right in the room.

Of course there are other ways to accomplish this, and ours may not even be the best way. But it works for us, and might work for you.

That’s it for now. If you have any questions, please leave a comment.

Leave a Reply

Your email address will not be published.