The Problem with Balconies

June 28, 2019

Sleuthhounds: Cruise is being built with the same game engine and tech that I used for the five previous Sleuthhounds games and the game jam Amelia Deerhart mini game. With six prior titles created, one would think that the engine would be quite mature and setup to handle everything I could throw at it with Cruise. For the most part, that is indeed the case. However, every now and then a challenge pops up that requires additions or alterations in the game engine. One such recent change has stemmed from the seemingly innocuous subject of balconies.

[Characters scaled to different sizes to match the perspective of a single floor room.]
Characters scaled to different sizes to match the perspective of a single floor room.

Within Cruise most of the rooms have their action take place horizontally. There will be a single floor in the room that characters move around on. One of the abilities of the engine is to shrink the sprites used to depict characters as they move farther away from camera so that they look like they fit the room’s perspective. On the technical side of things this is accomplished by saying that characters should display at a certain percentage of their size when they reach the bottom of the walkable area of the room and at a different, smaller percentage of their size when they reach the top of the walkable area. This can be seen in the above screenshot where Ampson appears smaller than Homes as she is closer to the top of the image.

This method of scaling characters works really well and requires very little effort to configure on a per room basis. However, with Cruise there are a few rooms that are divided vertically. By this I mean that they have an upper floor and a lower floor within them. For these rooms, the typical scaling system that I’ve just described produces some funky results. So:

[Single floor scaling made some characters teeny tiny when used in multi-floor rooms.]
Single floor scaling made some characters teeny tiny when used in multi-floor rooms.

The idea here is that there are two balconies, one vertically above the other. Since these balconies are the same distance from the virtual camera, characters standing on the top balcony should appear to be roughly the same size as those on the bottom balcony. However, using the standard scaling method the result is as shown. Characters on the upper balcony become really tiny.

Fortunately, the calculations for character sizes are all localized to a single routine in the game engine. It was a simple matter to expand the old scaling system, which only allowed for one pair of front and back scaling percentages per room, to allow for multiple pairs of scaling percentages. From there, all I had to do was add a way to assign which of the scaling pairs a given character should use. As such, characters standing on the upper balcony can now use different scaling pairs from those on the lower balcony. This allows all of the characters on both balconies to look like they’re roughly the same distance from the camera. The result is much better:

[All characters now appear perspective correct thanks to multi-floor scaling.]
All characters now appear perspective correct thanks to multi-floor scaling.

When expanding from the single scaling pair case to multiple scaling pairs I took care to do it in such a way that rooms that only have one floor in them, which is the vast majority of rooms in the game, would continue to work as expected with no scripting changes. In essence, when a new room is loaded the game engine assumes that the room only has one floor and that all characters are standing on that floor and are subject to its scaling factors. It’s only if the room script specifically tells the game engine that there are multiple scaling areas, and that certain characters are assigned to the non-default scaling area, that the new code kicks in.

Sharp eyed players of the previous Sleuthhounds games may notice that there are some rooms in those that do, in fact, feature balconies or other multiple floor situations. As a peek behind the curtain, in those cases multi-floor rooms were used so infrequently that a variety of hacks were done in the room scripts to make the multi-floor scaling work (or at least seem to work). However, Cruise has enough multi-floor rooms in it that it really became worth building in a system for handling them as opposed to reusing the hacks from the previous games. I’m quite happy with how the end result has turned out.