I want my project to handle different resolutions, for several devices. There are a lot of questions asking this out there, so I was able to setup a code to do it:
var defH = 600
var defW = 1024
#Change size of parent control to that of the complete viewport
#Using this MARGINS will work. Also, no need to resize everything, only options
#Get the scale
var newH = get_size().y
var scale = newH / defH
var options = get_node("options") #Get the buttons to resize
options.set_scale(scale * options.get_scale()) #Scale to new resolution
#Scale the margin so it keeps the proportions
options.set_margin(MARGIN_LEFT, options.get_margin(MARGIN_LEFT) * scale)
options.set_margin(MARGIN_TOP, options.get_margin(MARGIN_TOP) * scale)
This works pretty well when I go to
Project Settings > Display and I change
height. My buttons are re-scaled and re-positioned correctly.
However, when I export the app to Android, they are not correctly positioned. The scale works well though. However, is too much space between the right side of the screen and the buttons. My phone has a resolution of 800x480 px (in landscape) and screen size of 4.0''.
I set resolution of 800x480 in PC and everything works well. I wonder why it is not the same in Android. My best bet is that a device with the same screen size as mine can have a different resolution, and I should take that in account when repositioning. However, I don't know how to handle this. Any ideas? Thank you.