Page 1 of 1

Need help with aspect ratio and resolution

Posted: Tue Sep 11, 2018 6:33 pm
by xpali2
Okay so this is a problem that has puzzled me for the past 6 months. I am pretty much a beginner in coding a full game and am trying to make one for practice. I'm pretty much ready to give up on coding games all together if I can't fix this issue. I've looked for libraries that handle aspect ratio and resolution like TLfres but they are all outdated.

Anyway, my question is: What are the options for making a game work in different resolutions(Using pixel graphics that have been scaled up in logical increments such as 2x 4x 8x so they look the same)?. From what I understand it should be possible to simply change the window so it fits a smaller screen, where the graphics remain the same size. For example a base resolution in 16:9 1680 by 1050 and a different resolution that is in 4:3. Other players having a farther viewing range is not an issue.

If running this in resolutions with different aspect ratios is deemed impossible, then I also will have peace with the answer to the following question: How do I make it run on most resolutions of a 16:9 aspect ratio.

Any help at all either pointing to a library or a way I can achieve this myself would be greatly appreciated. Right now I am pretty much completely stuck.

Thanks,

Xpali2

Re: Need help with aspect ratio and resolution

Posted: Tue Sep 11, 2018 6:48 pm
by xpali2
This perfectly shows what I would like to achieve at about 0:16 https://www.youtube.com/watch?v=EcSyf5CoyaU

Re: Need help with aspect ratio and resolution

Posted: Wed Sep 12, 2018 12:35 am
by zorg
Do people not know how to use the search function? :3 I know, it's not the best...

Here you go: viewtopic.php?f=4&t=85638&p=222698#p222698

But for an extended answer, you have two options, if you want to keep your game pixel-perfect;
1. Choose one aspect ratio and use that with integral zoom levels (1x, 2x, 3x, 4x, 5x, etc.);
2. Calculate the nearest resolutions you'd be willing to show more (and less) of the world on the two axes using the aspect ratios you want to support, then do the same thing for all of those what you did in option 1.

Option two solves your issue, but it does present an issue itself, in that you must show a bit more and or less of the world, if you intend on keeping the visuals pixel-perfect.

To give you an example, OpenTTD works like this; it just shows more or less of the world, when resizing its window, and it also has an integral zoom function.



Also, just my 5 cents, but giving up because you can't write code like this seems to indicate to me that you should start with smaller projects instead; like pong or snake or tetris... this gets repeated ad nauseum everywhere, but for good reason; if you're not confident, you most likely can't pull off anything more complex.

If you're confident, then lack of skill is somewhat irrelevant since you have the drive to learn and reference stuff along the way... and that's actually somewhat expected, unless you prefer remembering every facet of löve, lua and whatever else you might need for a specific game (like "advanced" math, physics, color blending formulas, etc.).

Re: Need help with aspect ratio and resolution

Posted: Wed Sep 12, 2018 3:01 pm
by xpali2
zorg wrote: Wed Sep 12, 2018 12:35 am But for an extended answer, you have two options, if you want to keep your game pixel-perfect;
1. Choose one aspect ratio and use that with integral zoom levels (1x, 2x, 3x, 4x, 5x, etc.);
2. Calculate the nearest resolutions you'd be willing to show more (and less) of the world on the two axes using the aspect ratios you want to support, then do the same thing for all of those what you did in option 1.
.[/size]
Step one is clear to me. What exactly do you mean by the second point? If I would draw something to the top of the screen won't it still be different in the code? In one resolution you would have a y of say 1000 for the top of the screen while in a different resolution it falls off-screen.

Thanks for replying

Re: Need help with aspect ratio and resolution

Posted: Wed Sep 12, 2018 6:44 pm
by zorg
The world coordinates for 0,0 should still be 0,0; regardless of the camera's aperture dimensions. Just adjust how much of the world you're showing. And use a camera lib if you're not yet.

Re: Need help with aspect ratio and resolution

Posted: Thu Sep 13, 2018 12:44 pm
by xpali2
Ah yes I understand! I will be looking for a camera library then. Thanks