summaryrefslogtreecommitdiffstats
path: root/demo/Camera.gd
diff options
context:
space:
mode:
Diffstat (limited to 'demo/Camera.gd')
-rw-r--r--demo/Camera.gd13
1 files changed, 8 insertions, 5 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: