User chosen Screen Resolution

I think I have a handle on dealing with layout/resolution issues within a game. But based on my experience shipping for Windows, I will need to give players a way to choose whether to play full-screen or not, and what size 16:9 window. Unity has a configuration dialog that deals with this. I didn’t see a way to provide this with Corona (perhaps because its focus is mobile, where you don’t get to pick your screen size after buying the device).

whats the question?

I’ve been using this workaround:

config.lua

local loadsave = require( "spyric.loadsave" ) local path = system.pathForFile( "resolution.json", system.DocumentsDirectory ) local file = io.open( path, "r" ) local settings = {} if file then settings = loadsave.load( "resolution.json" ) io.close( file ) else settings.width = 320 settings.height = 480 loadsave.save( settings, "resolution.json" ) end application = { content = { width = settings.width, height = settings.height, scale = "letterBox", fps = 60, imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3, }, }, }

In the actual game, I have an options scene where the player can select their desired resolution and between fullscreen and windowed mode. Then, once the player is finished and they press “accept changes”, they are shown the usual “Please restart the game to apply new settings.”

[quote=“XeduR,post:3,topic:150875”]

I’ve been using this workaround:

config.lua

local loadsave = require( "spyric.loadsave" ) local path = system.pathForFile( "resolution.json", system.DocumentsDirectory ) local file = io.open( path, "r" ) local settings = {} if file then settings = loadsave.load( "resolution.json" ) io.close( file ) else settings.width = 320 settings.height = 480 loadsave.save( settings, "resolution.json" ) end application = { content = { width = settings.width, height = settings.height, scale = "letterBox", fps = 60, imageSuffix = { ["@2x"] = 1.5, ["@4x"] = 3, }, }, }

In the actual game, I have an options scene where the player can select their desired resolution and between fullscreen and windowed mode. Then, once the player is finished and they press “accept changes”, they are shown the usual “Please restart the game to apply new settings.” [/quote]

Just wanted to jump in to say this is actually ingenious. I’d never considered adding code to config.lua before, for anything!

How does this work alongside the values in the window table in build.settings? 

Nice use of executable Lua! I guess this answers the question of how to let the player pick resolution: you have to roll your own dialog (somehow showing only viable resolutions) and relaunch, rather than switch from within the game like many engines.

You can execute Lua code in build.settings as well. Simply start a new Corona project and copy this over the initial build settings.

build.settings

settings = { orientation = { default = "landscape", supported = { "landscape", }, }, window = { defaultMode = "windowed", defaultViewWidth = 960, defaultViewHeight = 640, suspendWhenMinimized = true, enableCloseButton = true, enableMinimizeButton = false, titleText = { default = "Original window settings" }, }, } -- Lua code can run here as well. local useThisInstead = true if useThisInstead then settings.window.defaultViewWidth = 220 settings.window.defaultViewHeight = 220 settings.window.titleText.default = "Conditional window settings" end

As you’d expect, if “useThisInstead” is set to true, then the window will be sized accordingly and the window’s title will be set to “Conditional window settings”.

I’m sure I tried this before, but clearly not! Had always assumed config.lua and build.settings were static data files.

Now that you mentioned it, I also remembered that there were some issues with code in build.settings, so I tried it out quick.

Seems like you can run simple code in build.settings, but requiring modules or using global libraries there won’t work. Now, if the game is set to fullscreen mode, I don’t know if the window width and height matter at all.

Asking GlitchGames or PonyWolf how they managed the resolution issue with their games could be useful.

 

Curious and I might not get chance to check before I forget about this - what happens if you try to read something like display.contentWidth at the top of config.lua? I’m wondering if there’s a way to grab the native display size before setting the size you want to work in. This might be useful in some cases…

If I remember correctly, both display.contentWidth and Height return -1 if used in config.lua.

Now, since Corona supports resizing the window via dragging with mouse (if enabled in build.settings), the the cleanest solution for supporting all resolutions and window sizes would probably be to dig in to Corona’s code and add two new native.setProperty() calls, something like native.setProperty( “windowWidth”, 1280) and native.setProperty( “windowHeight”, 720 ). I’m not sure how difficult something like that would be.

We rly need that bounty thing that people were talking about on another thread :smiley: I’d pay to get this done, same with mouse

I just had a quick peek at Corona’s GitHub page and I found that something most interesting was added a few days ago:

macOS/Windows: adding property ‘windowSize’ to native.setProperty()

* Added new native.setProperty() named “windowSize” for MacOS

This will allow you to change the window width/height in code by passing a table with either width or/and height values

* Added new native.setProperty() named “windowSize” for Windows

This will allow you to change the window width/height in code by passing a table with either width or/and height values

Co-authored-by: Marcel <marcelvdmade@gmail.com>

https://github.com/coronalabs/corona/commit/e99f0136326a1962dfa3be103a3411b815c827a9

 

So, this means that, probably starting from the the next daily build, we should be able to:

  1. Select any resolution via the loadsave trick, and

  2. Resize the window via native.setProperty( “windowSize”, { width=1280, height=720 } )

In other words, we will finally be able to fully manage the resolution of our apps for Windows and Mac builds!

just the mouse left and I’m a happy camper! :slight_smile: