How to set a curve (Path2D) to match the display?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hapc1

I want to make a path around the whole screen that spawns enemies, but when the screen’s height is higher than the base height that is set in the Project Settings, even tho the Stretch/Aspect is set to expand, the enemies will start spawning that much higher up when they are supposed to spawn at the bottom. I want to make it flexible so it works properly on every phone.

I guess I should use the OS.get_window_safe_area() in the Path2D.curve.add_point(), but I don’t know how. Or I might be completely wrong.

:bust_in_silhouette: Reply From: daughtersofcows

Hello. I would like to propose a solution that worked for me.

In Main scene script I would write:

func _ready():
screen_size = get_viewport_rect().size
# Clear all Vector2 points

# Set 1st vector
# Set 2nd vector
$MobPath.curve.add_point(Vector2(screen_size.x, 0))
# Set 3rd vector
$MobPath.curve.add_point(Vector2(screen_size.x, screen_size.y))
# Set 4th vector
$MobPath.curve.add_point(Vector2(0, screen_size.y))
# Set 5th vector
$MobPath.curve.add_point(Vector2(0, 0))