From f4381c59c1d239400fbd787fe3a5247f0c535460 Mon Sep 17 00:00:00 2001 From: Logan Date: Sun, 30 Apr 2023 18:51:05 -0600 Subject: Move to Godot 4 and fixes --- scripts/camera.gd | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'scripts/camera.gd') diff --git a/scripts/camera.gd b/scripts/camera.gd index 773ff75..9204a08 100644 --- a/scripts/camera.gd +++ b/scripts/camera.gd @@ -1,7 +1,7 @@ extends Camera2D -onready var basketball = $"../Basketball" -onready var hoop = $"../Hoop" +@onready var basketball = $"../Basketball" +@onready var hoop = $"../Hoop" func _process(_delta): if !basketball.waiting_for_shoot: @@ -16,22 +16,22 @@ func adjust_zoom(): # Min and max widths of the court we want visible on screen at once var min_width = dist_to_hoop + basketball.drag_radius * 3 var max_width = limit_right - limit_left - + var zoom_level = Vector2(1, 1) # Zoom out the camera if we need to show more on screen if min_width > limit_right: - zoom_level = zoom_level * (min_width / limit_right) + zoom_level /= (min_width / limit_right) # Width of the view when the zoom is set to 1 var view_width = get_viewport().get_visible_rect().size.x # Fit the zoom level within the max width if needed # TODO: There should also be a vertical limit - var max_zoom = float(max_width) / float(view_width) - zoom_level.x = clamp(zoom_level.x, 1, max_zoom) - zoom_level.y = clamp(zoom_level.y, 1, max_zoom) - + var max_zoom = float(view_width) / float(max_width) + zoom_level.x = clamp(zoom_level.x, max_zoom, 1) + zoom_level.y = clamp(zoom_level.y, max_zoom, 1) + set_zoom(zoom_level) func _on_Basketball_reset(): -- cgit v1.2.3