scaling the screen


Well, you maybe know it. After trying some small lua API you see there is no way of properly getting the game resolution to work from start. When my screen is 1900x800 pixels and the game is retro looking with only 256x128 resolution then you have to think outside the box.

The easy way is to make a camera class. For that i use library named SPRY. Then you do not care about the resolution, you smple scale it as needed.

So the equations are:

local screen_width = 256
local screen_height = 128
local scale_x = spry.window_width()/screen_width
local scale_y = spry.window_height()/screen_height

The result in this case will be:

scale_x = 1900/256 = 7.42 = math.ceil(7.42) -> 8
scale_y = 800/128 = 6.25 = math.ceil(6.25) -> 7

Make the scale round up so the scaling of the sprites does not look like a messy squishy jigger noodles.

Now you have 2 scaling numbers. By using them at the same time the image would look stretched more by width than height. And this is not desired.

So you either pick the smallest number and use it in spry.scale(6.25,6.25) function and you get an image that is fit into the screen of 1900x800 and you need to center it because there will be black borders.

Or pick the biggest number and the image will fit on width, but will overflow the height. It is again needed to center such screen but it will look better in the result to not have black borders around your game screen.

Window in most cases is resizeable. So you only need a camera class that calculates the correct scale of your own desired resolution and then it translates, scales the image of game components so it fits into the screen centered as needed.

What will the camera do? It will set the camera position so it looks at an object center but the object will look positioned in a center of the monitor screen. That means, when you move the object (player) the object appears as if in center of monitor while the game is scrolling other objects around by the player.

Then you do not need to much calculations that do the proper screen resolution scaling. It is just the camera that moves around the scene and showing only a part of scene that is really visible.

Leave a comment

Log in with itch.io to leave a comment.