[ANSWERED] Changing display scale after build

I was looking at things and wondering it’s possible to to change the display scale after the app / game has been built. For example, in the game I want to have a setting section which allows people to pick between stretch and letterbox. After they select I want the scale to change.

Ideally I’d want to do this at run time, but I’m not sure that would be possible. If I have to I could probably do it so they have to close the app and re-open in… an I doubt that would even be possible.

I’ve tried searching for this, but haven’t been able to find anything unfortunately. Any help people can offer on this would be… well, helpfull :wink: [import]uid: 133056 topic_id: 25614 reply_id: 325614[/import]

Hey Stevil,

No, build/config settings cannot be changed. Sorry! [import]uid: 52491 topic_id: 25614 reply_id: 103566[/import]

Didn’t think it would be possible, thought no harm in asking though!

Guess I’ll just stick with letter box then, think people would rather that than stretched out images.

Thanks for your help yet again, I guess thats another drink I owe you! [import]uid: 133056 topic_id: 25614 reply_id: 103612[/import]

Peach already confirmed for you that you can not change these settings on the fly. However the part where you say changing a setting and reloading the app would most likely be possible. As far as I am aware the config lua works like any other lua file in your project. You can setup a conditional and even load a setting from a text file you saved. It just runs once at the start of the app and thats it, no going back. The only odd thing, which you mentioned already, would be the requirement of exiting your app and restarting to see the change. [import]uid: 56820 topic_id: 25614 reply_id: 103624[/import]

I tried doing this but it wasn’t working, when I was doing it worked locally in the emulator, when I did it live it was just giving me messages that the application was corrupted.

This is the code I tried:-

file = system.pathForFile( "settings.lua", "/")  
wfh = io.open(file, "w" )  
if not wfh:write('scaleType = "zoomStretch"') then  
 print ("error")  
else  
 print ("written")  
end  
io.close( wfh)  

That was my original idea, but that errors out on me. I THINK corona builds the files and then after that they aren’t actually used anymore… maybe someone can confirm this? [import]uid: 133056 topic_id: 25614 reply_id: 103693[/import]

You can’t edit a lua file when your app is running. You need a settings text file. I did this for a test and it works fine on my iPod and iPhone.

local path = system.pathForFile( "settings.txt", system.DocumentsDirectory )  
local file = io.open( path, "r" )  
local screen = "letterbox"  
  
if file then  
 screen = (file:read( "\*a" )  
 io.close( file )  
end  
  
application =   
{  
 content =   
 {   
 width = 640,  
 height = 960,  
 scale = screen  
 },  
}  

Elsewhere in my main.lua I added this code to respond to a button for testing the changes. Killed the app and restarted. It was then zoomed as expected.

local path = system.pathForFile( "settings.txt", system.DocumentsDirectory )  
local file = io.open( path, "w" )  
file:write( "zoomEven" )  
io.close( file )  

[import]uid: 56820 topic_id: 25614 reply_id: 103751[/import]

Pretty slick solution…considering the same. [import]uid: 58455 topic_id: 25614 reply_id: 109286[/import]

As a thought exercise I started to ponder if it would be possible to basically completely duplicate the zoom functions within pure corona code, which would enable you to change it on the fly.
The answer, it seems to me, would be ‘yes’ - since you can mimic all of the zoom modes by just having a top level display group that you change the x and y scales of.

Also, I seem to recall someone posted code that showed you could actually get access to the core display ‘group’ (it isn’t exactly a display group, but it can be messed around with like one) - again, if true, you could just tweak its scaling values to replicate the zoom modes. [import]uid: 46639 topic_id: 25614 reply_id: 109292[/import]

In fact, how popular a feature would this be? If it were requested enough, I might consider looking into it myself and knocking up some kind of library to enable it. [import]uid: 46639 topic_id: 25614 reply_id: 109293[/import]

I think that would be pretty useful myself (you can do it with your TV, why not your mobile device?), but my client just informed me that they’re not too concerned about black bars on some devices, so it’s not as urgent.

[import]uid: 58455 topic_id: 25614 reply_id: 109323[/import]