2025-08-28 08:15:18 +08:00
|
|
|
@tool
|
2025-08-28 06:49:50 +08:00
|
|
|
extends Camera2D
|
2025-08-28 08:15:18 +08:00
|
|
|
class_name CameraManager
|
|
|
|
|
|
2025-08-28 12:00:09 +08:00
|
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
|
|
|
|
|
2025-08-28 14:15:01 +08:00
|
|
|
var shakeIntensity: float = 0
|
2025-08-28 11:14:14 +08:00
|
|
|
|
|
|
|
|
static var instance: CameraManager = null
|
2025-08-28 08:15:18 +08:00
|
|
|
|
|
|
|
|
func _ready():
|
2025-08-28 11:14:14 +08:00
|
|
|
instance = self
|
2025-08-28 08:15:18 +08:00
|
|
|
func _physics_process(_delta):
|
|
|
|
|
if is_instance_valid(UIState.player):
|
|
|
|
|
position = UIState.player.position
|
2025-08-28 14:15:01 +08:00
|
|
|
position += MathTool.randv2_range(shakeIntensity)
|
2025-08-28 11:14:14 +08:00
|
|
|
|
2025-08-28 14:15:01 +08:00
|
|
|
static func shake(millseconds: int, intensity: float = 10):
|
|
|
|
|
instance.shakeIntensity += intensity
|
2025-08-28 11:14:14 +08:00
|
|
|
await TickTool.millseconds(millseconds)
|
2025-08-28 14:15:01 +08:00
|
|
|
instance.shakeIntensity -= intensity
|
2025-08-28 12:00:09 +08:00
|
|
|
static func playAnimation(animation: String):
|
|
|
|
|
instance.animator.play(animation)
|