Letterbox rendering with black bars

#1

Hi.

I’d like to know how to use a design resolution of 1920 x 1080 (so that I can manipulate the game as it is an HD resolution) and use any resolution (say it 960 x 540) to project the game, and, in the case the window resolution doesn’t match the aspect ratio, add horizontal bars, one above and one below.

The second case I’d like to implement is to use a game design resolution of 256 x 224 and when the window doesn’t match the aspect ratio, add vertical bars, one to the left and one to the right.

How do I achieve that? I’m kind of lost. I’ve tried configuring display profiles but nothing seems to work.

Thanks!

0 Likes

#2

This isn’t hard to do, but it isn’t something that Defold will do for you with any built-in settings. Take a look at the Render manual. The default render script offers a few different ways to scale things, though it does not do letterboxing. For that you will need to change the viewport in the render script update function, with render.set_viewport(x, y, width, height). You just need to calculate the correct rectangle that fits inside the window while matching your 16:9 aspect ratio (or whatever you like).

Hmm, and I don’t like to push my own stuff, but if you want to get letterboxing with the minimum of effort you can take a look at Rendercam. You can change camera settings in the Defold editor and use the “Fixed Aspect Ratio” and “View Area” options to do what you want. Like anything you don’t write yourself, it may not work exactly the way you expect, and comes with a lot of extra stuff.

2 Likes

#3

Thanks, it works like a charm.

There is one bug though, I have a collection loaded and it uses a camera, fixed aspect ratio of 256 x 224, and after I load another collection, different camera, same fixed aspect ratio, the camera displays in the center but tiny, instead of fully stretched as it would if we preserved the original camera.

0 Likes