I have decided to invoke martial law and poetic license on present and future posts, because my grammar is admittedly awful and I love colons and parentheses. This post will detail distance scaling, and is intended for novice game developers.
I haven't yet mentioned my other project, codenamed "Inquisitor," on this site. It is intended to be a Love2D-based framework that allows for easy creation of visual novels and point-and-click adventure games.
One of the speed bumps I have encountered during coding is addressing the myriad screen resolutions offered on desktop and laptop computers. I recently souped up a solution to provide letterboxes for screen resolutions that were not of a 16:9 ratio. The letterboxes can also orient themselves on the left and right sides of the screen if you played the game on a ridiculously wide screen.
The letterbox fix still doesn't solve the issue of where characters would be positioned on screen. While scaling and placing the background image would be incredibly easy for all scenarios, using pixels to designate where character images will be located in not as simple a task. As you may imagine, specifying a set pixel distance for the characters will look very different on many screens. Characters could end up being extremely close or far away from each other depending on your resolution. Directly using the coordinate system as-is with absolute pixel positions will cause you to lose every time.
My favorite thing to do when tackling a problem like this is to lie down on my bed and meditate on the problem at hand. I observed the bumps on my ceiling and pretended they were stars in the night sky; then, I had a sudden realization. I may not be able to solve the issue by translating the coordinate system as a whole, but I could implement a system for relative positions.
To elaborate, I thought of the way the Earth and Sun are positioned in the universe. Centering my coordinate system on the Sun and specifying 93 million pixel "miles" would be great for getting the distance between the two bodies correct, but I would still have a bunch of weird-looking darkness around the two bodies. Instead, I'm going to have my own
astronomical unit for my project.
The astronomical unit is fantastic when measuring distances between bodies in areas of cosmic scale. The distance between the Earth and the Sun is 1 A.U., and not 93,000,000 miles. For the purposes of Inquisitor, I'm not dealing with monitors of cosmic scale, but I do have to scale the distance between my game elements to make the experience uniform across different setups. In other words, after translating my coordinate system such that the origin (where x = 0 and y = 0) is at the center of the screen, I will make the distance between the origin and the left side of the screen equal one "astronomical unit." In this case, I can ensure that the position of characters on the screen will be consistent with respect to other characters and the screen's borders.
This problem is nominally more interesting than the letterbox problem, and can be fixed if you have basic knowledge of fractions and algebra. If you are currently trying to solve this problem, or have some tips you'd like to swap, feel free to comment and/or
follow my feed.