diff options
Diffstat (limited to 'demo')
-rw-r--r-- | demo/Camera.gd | 13 | ||||
-rw-r--r-- | demo/Main.gd | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/demo/Camera.gd b/demo/Camera.gd index 0dc6074..93ae41c 100644 --- a/demo/Camera.gd +++ b/demo/Camera.gd @@ -1,5 +1,7 @@ extends Camera2D +const MAX_ZOOM = 1 + var margin :Vector2 var window : Vector2 var map_center : Vector2 @@ -7,15 +9,16 @@ var texture_size : Vector2 var zoom_boundaries : Vector2 func _ready(): - margin = Vector2(0, 0) + margin = Vector2(50, 50) func configure(w : Vector2, c : Vector2, ts : Vector2) -> void: window = w map_center = c texture_size = ts - var zout : float = max((texture_size.x + margin.x) / window.x, (texture_size.y + margin.y) / window.y) - zoom_boundaries = Vector2(zout - 0.5, zout) - update_camera(0, 0, zoom_boundaries.y) + var zout : float = min(window.x / (texture_size.x + margin.x), window.y / (texture_size.y + margin.y)) + zoom_boundaries = Vector2(zout, zout + MAX_ZOOM) + zoom = Vector2(zout, zout) + position = map_center func update_camera(x : float, y : float, z : float) -> void: if z != 0: @@ -23,7 +26,7 @@ func update_camera(x : float, y : float, z : float) -> void: zoom.y = zoom.x position.x += x position.y += y - var delta = texture_size + margin - (window * zoom.x) + var delta = texture_size + margin - (window / zoom.x) if (delta.x <= 0): position.x = map_center.x else: diff --git a/demo/Main.gd b/demo/Main.gd index 8aad56f..50c0ab6 100644 --- a/demo/Main.gd +++ b/demo/Main.gd @@ -29,7 +29,7 @@ func on_rotate() -> void: on_viewport_resized() func on_zoom(b : bool) -> void: - Camera.update_camera(0, 0, -0.05 if b else 0.05) + Camera.update_camera(0, 0, 0.05 if b else -0.05) func on_toggle() -> void: Map.set_mode(UI.get_node("LOS").is_pressed(), UI.get_node("Move").is_pressed(), UI.get_node("Influence").is_pressed()) |