PirateTreasureHunt/GameCamera.gd

25 lines
676 B
GDScript

extends Camera2D
var Widgets
# Called when the node enters the scene tree for the first time.
func _ready():
Widgets = get_node("Widgets")
pass # Replace with function body.
func _process(_delta):
var win_size = OS.get_window_safe_area().size
Widgets.margin_left = -win_size.x * 0.5
Widgets.margin_top = -win_size.y * 0.5
pass
func screenToWorld(pos):
var screen_size = OS.get_window_safe_area().size
print ("pos", pos)
print ("Screen size: ", screen_size)
var camera_coords = pos - screen_size * 0.5
print ("Camera coords: ", camera_coords)
var world_coords = camera_coords + self.transform.origin
print ("world coords: ", world_coords)
return world_coords