mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 15:44:42 -04:00
Added smooth zooming
Camera zooming with the help of a Tween node, toggle-able in the Preferences
This commit is contained in:
parent
12fb8b02c8
commit
e677824f48
5 changed files with 56 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
extends Camera2D
|
||||
|
||||
var tween : Tween
|
||||
var zoom_min := Vector2(0.005, 0.005)
|
||||
var zoom_max := Vector2.ONE
|
||||
var viewport_container : ViewportContainer
|
||||
|
@ -7,6 +8,8 @@ var drag := false
|
|||
|
||||
func _ready() -> void:
|
||||
viewport_container = get_parent().get_parent()
|
||||
tween = Tween.new()
|
||||
add_child(tween)
|
||||
|
||||
func _input(event : InputEvent) -> void:
|
||||
var mouse_pos := viewport_container.get_local_mouse_position()
|
||||
|
@ -26,11 +29,22 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
# Zoom Camera
|
||||
func zoom_camera(dir : int) -> void:
|
||||
var zoom_margin = zoom * dir / 10
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
zoom += zoom_margin
|
||||
if Global.smooth_zoom:
|
||||
var zoom_margin = zoom * dir / 5
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
tween.interpolate_property(self, "zoom", zoom, zoom + zoom_margin, 0.05, Tween.TRANS_LINEAR, Tween.EASE_IN)
|
||||
tween.start()
|
||||
|
||||
if zoom > zoom_max:
|
||||
zoom = zoom_max
|
||||
if zoom > zoom_max:
|
||||
tween.stop_all()
|
||||
zoom = zoom_max
|
||||
|
||||
else:
|
||||
var zoom_margin = zoom * dir / 10
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
zoom += zoom_margin
|
||||
|
||||
if zoom > zoom_max:
|
||||
zoom = zoom_max
|
||||
if name == "Camera2D":
|
||||
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue