Hey guys, I have been trying to make a simple puzzle game for mobile devices. But I did not find any suitable solution. I have made a code to solve this.
Project > Display > Window >
Mode = 2d
Aspect = expand
Note: My design PSD size is (800, 1280) and I want a fixed screen height size (1280), width could be anything, I will adjust the width by code. Also, this code adjusts safearea.
Please test the code guys. Let me know if you guys using any better solution.
var design_size = Vector2(800.0, 1280.0)
var design_ratio = design_size.x / design_size.y
var safe_area = OS.get_window_safe_area()
var screen_size = get_viewport().get_visible_rect().size
screen_size.y -= safe_area.position.y
var screen_ratio = screen_size.x / screen_size.y;
var new_size = screen_size
if(screen_ratio < design_ratio):
var ww = design_size.y * screen_ratio
var hh = ww / screen_ratio
new_size = Vector2(ww, hh)
get_viewport().set_size_override(true, new_size, Vector2(0, safe_area.position.y/2))