Page 1 of 2
keep aspect ratio in several resolutions
Posted: Mon Apr 02, 2018 11:58 pm
by brunuu
I'm trying to find a way for my game to always keep the same ratio regardless of the resolution on android, so far I have not figured out a functional way
What's the best way to do this?
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 3:09 am
by zorg
Hi and welcome to the forums;
Depends on which of the two solutions you prefer, black boxes or the screen being cut off.
You'll have to have an "internal" resolution that has the aspect ratio you want, then you can either adjust the screen to the smallest (if you want vertial/horizontal black boxes) or the largest (if you want the screen to be cut off) of the two dimensions the user's screen has.
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 8:40 am
by brunuu
the screen and the objects can not be resized?
edit---
Does this solve the problem?
love.window.setFullscreen (true, "desktop")
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 9:04 am
by zorg
If my google translate is correct, you can resize the screen and scale the drawn objects as well, but it's way more cumbersome to calculate such things than to stick with one resolution, and scale THAT once.
(And i don't think any fullscreen mode on handhelds would do anything with the display in the way you would want it to)
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 9:49 am
by brunuu
zorg wrote: ↑Tue Apr 03, 2018 9:04 am
If my google translate is correct, you can resize the screen and scale the drawn objects as well, but it's way more cumbersome to calculate such things than to stick with one resolution, and scale THAT once.
(And i don't think any fullscreen mode on handhelds would do anything with the display in the way you would want it to)
Sorry, I have no idea why I started writing on another language, I'm still sleeping
The problem I'm facing is that I need the game to fit any resolution, more specifically on Android.
I can not use black bars or crop the screen
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 10:49 am
by zorg
If you don't want to use black bars OR crop the screen, then you only have two other methods to choose from:
Stretch the contents, or show more/less depending on the width and height.
Do choose one of those and i'll try to write a short code block on how to implement that.
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 12:24 pm
by brunuu
Stretching would be better, I guess
is for a smartphone screen after all
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 12:31 pm
by NotARaptor
Stretching would probably look bad. What sort of game are you trying to make?
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 12:49 pm
by brunuu
NotARaptor wrote: ↑Tue Apr 03, 2018 12:31 pm
Stretching would probably look bad. What sort of game are you trying to make?
is a strategy game with some GUI-like elements
Re: keep aspect ratio in several resolutions
Posted: Tue Apr 03, 2018 1:31 pm
by NotARaptor
Divide the "stuff to draw" into two main lists - the world and the GUI.
The world... well you'll just have to draw a smaller portion of it for smaller screens.
For the GUI, position everything relative to the general borders of the screen - i.e. "20 pixels from the right border, 10 pixels from the top border", then test it in every resolution you can to make sure things don't overlap or go strange.
I would definitely advise against stretching (that's when the things are drawn with uneven scaling on X/Y - they end up looking really tall and skinny, or short and wide... even a little bit is noticeable)