Bladeren bron

Adapt zoom rate when screen size changes

DricomDragon 4 jaren geleden
bovenliggende
commit
6680ab61c0
1 gewijzigde bestanden met toevoegingen van 12 en 4 verwijderingen
  1. 12 4
      MainCamera.gd

+ 12 - 4
MainCamera.gd

@@ -1,13 +1,16 @@
 extends Camera2D
 
-export var dist_max = 900
-export var zoom_rate = 0.001
+export var zoom_border = 100
 
-var view
+var zoom_rate:float
+
+var view:Viewport
+var dist_max:float
 
 func _ready():
 	view = get_tree().root
 	view.connect("size_changed", self, "_on_size_changed")
+	update_zoom_reference()
 
 func _process(_d):
 	move()
@@ -47,5 +50,10 @@ func center_on(players):
 
 	zoom = Vector2(new_zoom, new_zoom)
 
+func update_zoom_reference():
+	var ref_length = min(view.size.x, view.size.y)
+	dist_max = ref_length - 2 * zoom_border
+	zoom_rate = 1.0 / dist_max
+
 func _on_size_changed():
-	print("New size :", view.size)
+	update_zoom_reference()