0 votes

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))
Godot version 3.3.2
in Engine by (16 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.