0 votes

I've made a system that change the CanvasLayers offset to smoothly change between screens, like a scrolling effect. But, this only works on the default resolution (320x180). How I can change the offsets based on the game resolution, since it'll be scaled to the device resolution? (For example, this works on 1280x720 because it's in the same aspect ratio, but don't work on ultrawide )
All the screens
The offsets math is: -320*n

The problem

One of the solutions is changing all the offsets on _ready() to fit the aspect ratio of the game, but since the default resolution is low, I can't find a way to do this.

asked Jun 19 in Engine by INKnight (37 points)
edited Jun 19 by INKnight

get_viewport_rect().size

1 Answer

0 votes
Best answer
tool
extends Control

func _ready() -> void:
    Utility.ok(get_node("..").connect("resized", self, "_onResized"))

func _onResized() -> void:
    var tex := rect_size
    var win := get_viewport_rect().size
    if win.x > win.y:
        rect_rotation = 90
        rect_scale = Vector2(win.y / tex.x, win.x / tex.y)
    else:
        rect_rotation = 0
        rect_scale = Vector2(win.x / tex.x, win.y / tex.y)

https://gotm.io/henry-software/pixelleveltest

answered Jun 19 by rakkarage (805 points)
selected Jun 22 by INKnight
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 How to use this Q&A? before posting your first questions.