44 lines
		
	
	
	
		
			755 B
		
	
	
	
		
			GDScript
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
	
		
			755 B
		
	
	
	
		
			GDScript
		
	
	
	
	
	
| extends Sprite2D
 | |
| 
 | |
| @export var powerOnCurve: Curve
 | |
| @export var shutDownCurve: Curve
 | |
| var time: float
 | |
| @export var duration: float
 | |
| 
 | |
| @export var bubbleMask: Sprite2D
 | |
| 
 | |
| var curve: Curve
 | |
| var animating: bool = false
 | |
| 
 | |
| 
 | |
| # Called every frame. 'delta' is the elapsed time since the previous frame.
 | |
| func _process(delta):
 | |
| 	if (not animating):
 | |
| 		return
 | |
| 	
 | |
| 	time += delta
 | |
| 	var alpha = curve.sample(clamp(time / duration, 0, 1))
 | |
| 	modulate = Color(Color.WHITE, alpha)
 | |
| 	bubbleMask.modulate = Color(Color.WHITE, alpha)
 | |
| 	if (time >= duration):
 | |
| 		animating = false
 | |
| 
 | |
| 
 | |
| func shut_down():
 | |
| 	time = 0
 | |
| 	curve = shutDownCurve
 | |
| 	animating = true
 | |
| 
 | |
| 
 | |
| func power_on():
 | |
| 	time = 0
 | |
| 	curve = powerOnCurve
 | |
| 	animating = true
 | |
| 
 | |
| 
 | |
| func _on_lights_out():
 | |
| 	shut_down()
 | |
| 
 | |
| 
 | |
| func _on_lights_in():
 | |
| 	power_on()
 | 
