-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScreenShake.gd
44 lines (30 loc) · 979 Bytes
/
ScreenShake.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
extends Node
const TRANS = Tween.TRANS_SINE
const EASE = Tween.EASE_IN_OUT
var amplitude = 0
var priority = 0
onready var camera = get_parent()
func start(duration = 0.2, frequency = 15, amplitude = 16, priority = 0):
if (priority >= self.priority):
self.priority = priority
self.amplitude = amplitude
$Duration.wait_time = duration
$Frequency.wait_time = 1 / float(frequency)
$Duration.start()
$Frequency.start()
_new_shake()
func _new_shake():
var rand = Vector2()
rand.x = rand_range(-amplitude, amplitude)
rand.y = rand_range(-amplitude, amplitude)
$ShakeTween.interpolate_property(camera, "offset", camera.offset, rand, $Frequency.wait_time, TRANS, EASE)
$ShakeTween.start()
func _reset():
$ShakeTween.interpolate_property(camera, "offset", camera.offset, Vector2(), $Frequency.wait_time, TRANS, EASE)
$ShakeTween.start()
priority = 0
func _on_Frequency_timeout():
_new_shake()
func _on_Duration_timeout():
_reset()
$Frequency.stop()