Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

User chosen Screen Resolution
Started by david755 Jan 02 2020 08:56 AM

13 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

david755

[GLOBAL: userInfoPane.html]
david755
  • Observer

  • 3 posts
  • Corona SDK

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).



[TOPIC: post.html]
#2

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 170 posts
  • Corona SDK

whats the question?

[TOPIC: post.html]
#3

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

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."


  • Michael Flad, ldurniat, nick_sherman and 1 other like this

[TOPIC: post.html]
#4

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 544 posts
  • Corona SDK

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."

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

[TOPIC: post.html]
#5

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

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



[TOPIC: post.html]
#6

david755

[GLOBAL: userInfoPane.html]
david755
  • Observer

  • 3 posts
  • Corona SDK

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.



[TOPIC: post.html]
#7

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

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".


  • nick_sherman likes this

[TOPIC: post.html]
#8

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,960 posts
  • Corona SDK

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



[TOPIC: post.html]
#9

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

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.

 



[TOPIC: post.html]
#10

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 544 posts
  • Corona SDK

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...

[TOPIC: post.html]
#11

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

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.



[TOPIC: post.html]
#12

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 170 posts
  • Corona SDK

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

[TOPIC: post.html]
#13

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,176 posts
  • Corona SDK

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!


  • OlinaChang and pixec like this

[TOPIC: post.html]
#14

pixec

[GLOBAL: userInfoPane.html]
pixec
  • Contributor

  • 170 posts
  • Corona SDK

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


[topic_controls]
[/topic_controls]