1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-06-10 21:57:12 +08:00

feat(状态条): 添加血量变化延迟动画和强制同步功能

- 在ColorBar中添加lastChangeTime记录最后变化时间,配合GameRule.detainTime实现血量变化延迟动画
- 新增forceSync方法用于强制同步状态条显示
- 调整EntityBase初始化顺序,确保状态条正确初始化
- 在GameRule中添加detainTime配置项控制动画延迟时间
This commit is contained in:
2025-09-06 16:51:12 +08:00
parent 290a1bbef0
commit 73e34e07d2
4 changed files with 18 additions and 5 deletions
+9 -3
View File
@@ -15,6 +15,7 @@ class_name ColorBar
var middleValue = 0
var frontValue = 0
var forwardDirection = -1
var lastChangeTime = 0
func getPercent(value: float):
return (value - minValue) / (maxValue - minValue)
@@ -23,13 +24,18 @@ func setCurrent(value: float):
return
forwardDirection = sign(value - currentValue)
currentValue = clamp(value, minValue, maxValue)
func _ready():
lastChangeTime = WorldManager.getTime()
func forceSync():
middleValue = currentValue
frontValue = currentValue
func _ready():
forceSync()
lastChangeTime = WorldManager.getTime()
func _draw():
draw_style_box(backBox, Rect2(0, 0, size.x, size.y))
draw_style_box(middleBox2 if forwardDirection > 0 else middleBox1, Rect2(0, 0, size.x * getPercent(middleValue), size.y))
if WorldManager.getTime() - lastChangeTime > GameRule.detainTime:
draw_style_box(middleBox2 if forwardDirection > 0 else middleBox1, Rect2(0, 0, size.x * getPercent(middleValue), size.y))
draw_style_box(frontBox, Rect2(0, 0, size.x * getPercent(frontValue), size.y))
func _physics_process(_delta: float) -> void:
middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2)