forked from Chaitanyassr/Obesity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScreenShake.gd
43 lines (30 loc) · 961 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
extends Node
var amplitude = 0
var TRANS = Tween.TRANS_SINE
var EASE = Tween.EASE_IN_OUT
onready var Camera2D = get_parent()
var priority = 0
func start(duration = 1, timer = 15, amplitude = 16, priority = 0):
if priority >= self.priority:
self.priority = priority
self.amplitude = amplitude
$Duration.wait_time = duration
$Timer.wait_time = 1 / float(timer)
$Duration.start()
$Timer.start()
_new_shake()
func _new_shake():
var rand = Vector2()
rand.x = rand_range(-amplitude, amplitude)
rand.y = rand_range(-amplitude, amplitude)
$ShakeTween.interpolate_property(Camera2D, "offset", Camera2D.offset, rand, $Timer.wait_time, TRANS, EASE)
$ShakeTween.start()
func _reset():
$ShakeTween.interpolate_property(Camera2D, "offset", Camera2D.offset, Vector2(200, 0), $Timer.wait_time, TRANS, EASE)
#$ShakeTween.start()
priority = 0
func _on_Timer_timeout():
_new_shake()
func _on_Duration_timeout():
_reset()
$Timer.stop()