Problem: When you want to set your window resolution (window mode) in your settings menu you have to make a selection of different resolutions which should be available for your game. All hardcoded.
Here its difficult to pick the right choices from the start because you normally don't know if a resolution you make available here is supported by the monitor of the player or if you just give too less options (max resolution is 1920x1080 but the player has a 8k monitor --> too small window).
The other way around this can end up in an e.g. 1920x1080 pixel window on a 1600x900 pixel monitor which is not that gooood.
Of course you can make your window resizable, but i find this a bit too wanky and unprecisely.
BUT BEHOOOOLD!
Solution: You have to check the available screen resolutions from the players monitor and present the player only the resolutions which are less than or eqeal your monitors resolutions.
Discovering the possibility to check which resolutions the players display supports (Thanks to SimonS) I made a script which checks them for 16:9 aspect ratio and add them to a table.
I also made it sorted from low to high because the normal visionaire function has them unsorted (for me) . So mainly my script sorts them right and adds only wanted ratios inside a new table to work with.
You can edit your settings/config menu/scripts to check against this table.
Here is how:
Inside a definition script i set a global table
Also i created a function with the same name which gets all display resolutions and adds only these to the displayModes table which are 16:9
-- * get all Display Resolutions and put them in the displayModes Table * --
function DisplayModes()
local modes = system.getDisplayModes() --builtin Visionaire function returns all display resolutions
displayModes[1] = "384x216" -- insert hardcoded supported resolution sizes
displayModes[2] = "768x432"
displayModes[3] = "1152x648"
displayModes[4] = "1536x864"
for k,v in spairs(modes, function(t,a,b) return t[b] < t[a] end) do
if is16x9(k) then
table.insert(displayModes,k) -- add all 16:9 resolutions supported by the display
end
end
end
-- * determine if a given resolution string XxY is 16:9 aspect ratio* --
function is16x9(res_string)
local res = {}
for i in string.gmatch(res_string, '([^x]+)') do table.insert(res,i) end -- res[1] = width , res[2] = height
if tonumber(res[2]) == (tonumber(res[1])/16)*9 then return true else return false end
end
-- * sort functions for keys * --
function spairs(t, order) -- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end -- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys (order function is "function(t,a,b) return t[b] < t[a] end)")
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
now the lua table displayModes has all the 16:9 resolutions for the current players monitor + some hard coded inside to check against in your config file or make them available in your settings menu.
In your game config loading script you can use this:
DisplayModes()
print("- - DISPLAY 16:9 RESOLUTIONS - -")
for i=1, #displayModes do
print(" "..string.format("%02d",i)..": "..displayModes[i])
end
which will print all the items of the table to your log.
Maybe its useful for some of you. =)
~Sebastian