-
-
Save mrkdji/9ea07258c22c3ac049c52ec58a8e3a0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends TriggerGameEvent | |
export var zoom_to_fit : bool = false; | |
export var scale_to_apply : float = 1.0; | |
export var tween_duration : float = 0.5; | |
onready var tween = $Tween; | |
var former_scale = null | |
func _ready(): | |
if zoom_to_fit: | |
call_deferred("do_zoom_to_fit"); | |
func do_zoom_to_fit(): | |
var scale_x = get_viewport_rect().size.x / get_trigger_area_rect().size.x; | |
var scale_y = get_viewport_rect().size.y / get_trigger_area_rect().size.y; | |
scale_to_apply = max(scale_x, scale_y); | |
func on_body_entered(_body): | |
if former_scale == null: | |
former_scale = Globals.camera.scale; | |
tween.stop_all(); | |
tween.interpolate_method( | |
Globals.camera, | |
"adjust_scale", | |
Globals.camera.scale, | |
Vector2.ONE * scale_to_apply, | |
tween_duration); | |
tween.start(); | |
pass; | |
func on_body_exited(_body): | |
tween.stop_all(); | |
tween.interpolate_method( | |
Globals.camera, | |
"adjust_scale", | |
Globals.camera.scale, | |
former_scale, | |
tween_duration); | |
tween.start(); | |
pass; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment