mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-27 22:41:56 +08:00
0d3c1790af
实现鼠标位置影响相机偏移的功能,使相机能够根据鼠标在屏幕上的位置进行轻微偏移,提升游戏交互体验
37 lines
1.2 KiB
GDScript
37 lines
1.2 KiB
GDScript
@tool
|
|
extends Camera2D
|
|
class_name CameraManager
|
|
|
|
@export var constantOffset: Vector2 = Vector2.ZERO
|
|
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
|
|
|
var shakeIntensity: float = 0
|
|
var shaking: bool = false
|
|
|
|
static var instance: CameraManager = null
|
|
|
|
func _ready():
|
|
instance = self
|
|
func _physics_process(_delta):
|
|
if is_instance_valid(UIState.player):
|
|
position = UIState.player.position + constantOffset
|
|
position += MathTool.sampleInCircle(shakeIntensity)
|
|
position += MouseTool.getPositionByScreen(Vector2.ONE * 0.5, self ) / 2
|
|
|
|
static func shake(millseconds: float, intensity: float = 10, steper: Callable = func(currentValue, _totalValue, _restPercent): return currentValue):
|
|
if StarterPanel.buildingShader: return
|
|
var startTime = WorldManager.getTime()
|
|
instance.shakeIntensity = intensity
|
|
await TickTool.until(
|
|
func():
|
|
instance.shakeIntensity = steper.call(instance.shakeIntensity, intensity, 1 - (WorldManager.getTime() - startTime) / millseconds)
|
|
return WorldManager.getTime() - startTime >= millseconds || !instance.shaking
|
|
)
|
|
instance.shakeIntensity = 0
|
|
static func shakeStop():
|
|
instance.shaking = false
|
|
instance.shakeIntensity = 0
|
|
static func playAnimation(animation: String):
|
|
instance.animator.play(animation)
|