commit 797541b0e2373b08d96692c865962585daee4c4f
parent 707d21d3835b1480a4b7a0f65abac6186bb9eb32
Author: FIGBERT <figbert@figbert.com>
Date: Thu, 11 Feb 2021 21:53:35 -0800
Make 2D viewport responsive for various screens
The app should now resize properly in the 16:9 aspect
ratio and also compensate for vertical notches.
Diffstat:
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/project.godot b/project.godot
@@ -22,8 +22,11 @@ config/icon="res://icon.png"
[display]
window/size/width=1080
-window/size/height=2338
+window/size/height=1920
+window/dpi/allow_hidpi=true
window/handheld/orientation="portrait"
+window/stretch/mode="2d"
+window/stretch/aspect="keep_width"
[rendering]
diff --git a/src/scenes/main.tscn b/src/scenes/main.tscn
@@ -11,9 +11,8 @@ font_data = ExtResource( 2 )
script = ExtResource( 1 )
[node name="Label" type="RichTextLabel" parent="."]
-margin_top = 150.0
-margin_right = 1080.0
-margin_bottom = 2338.0
+anchor_right = 1.0
+anchor_bottom = 1.0
custom_fonts/normal_font = SubResource( 1 )
scroll_following = true
__meta__ = {
diff --git a/src/scripts/main.gd b/src/scripts/main.gd
@@ -201,6 +201,8 @@ func _initialize_client() -> void:
get_tree().network_peer = peer
get_tree().connect("connected_to_server", self, "_client_connected_successfully")
get_tree().connect("connection_failed", self, "_client_connection_failed")
+ var safe_area := OS.get_window_safe_area()
+ $Label.set_margin(MARGIN_TOP, safe_area.position.y)
func _client_connected_successfully() -> void: