pro animated sprite update
This commit is contained in:
parent
8ee184e33b
commit
1d383a58d2
@ -1,6 +1,8 @@
|
|||||||
@tool
|
@tool
|
||||||
class_name ProAnimatedSprite2D extends AnimatedSprite2D
|
class_name ProAnimatedSprite2D extends AnimatedSprite2D
|
||||||
|
|
||||||
|
signal position_updated(global_pos: Vector2)
|
||||||
|
|
||||||
@export var autostart := true
|
@export var autostart := true
|
||||||
@export var action_configs: Array[Dictionary] = []
|
@export var action_configs: Array[Dictionary] = []
|
||||||
@export var move_configs: Array[Dictionary] = []
|
@export var move_configs: Array[Dictionary] = []
|
||||||
@ -46,7 +48,7 @@ static func new_action_config() -> Dictionary:
|
|||||||
return ACTION_CONFIG.duplicate()
|
return ACTION_CONFIG.duplicate()
|
||||||
|
|
||||||
|
|
||||||
@onready var debug_mov_onion_sprite2d = $DebugMovOnionSkinSprite2D as Sprite2D
|
var debug_mov_onion_sprite2d: Sprite2D
|
||||||
|
|
||||||
# 从 intro 到 next 的配置信息
|
# 从 intro 到 next 的配置信息
|
||||||
var auto_checkout_dict = {
|
var auto_checkout_dict = {
|
||||||
@ -73,12 +75,16 @@ func _ready() -> void:
|
|||||||
animation_finished.connect(_on_animation_finished)
|
animation_finished.connect(_on_animation_finished)
|
||||||
animation_looped.connect(_on_animation_finished)
|
animation_looped.connect(_on_animation_finished)
|
||||||
# 处理 debug_mov_onion_sprite2d
|
# 处理 debug_mov_onion_sprite2d
|
||||||
|
debug_mov_onion_sprite2d = get_node_or_null("DebugMovOnionSkinSprite2D")
|
||||||
if Engine.is_editor_hint():
|
if Engine.is_editor_hint():
|
||||||
# stop()
|
if not debug_mov_onion_sprite2d:
|
||||||
# frame = 0
|
debug_mov_onion_sprite2d = Sprite2D.new()
|
||||||
|
add_child(debug_mov_onion_sprite2d)
|
||||||
|
debug_mov_onion_sprite2d.name = "DebugMovOnionSkinSprite2D"
|
||||||
|
debug_mov_onion_sprite2d.modulate.a = 0.5
|
||||||
debug_playing = false
|
debug_playing = false
|
||||||
_debug_mov_projection()
|
_debug_mov_projection()
|
||||||
else:
|
elif debug_mov_onion_sprite2d:
|
||||||
debug_mov_onion_sprite2d.queue_free()
|
debug_mov_onion_sprite2d.queue_free()
|
||||||
# autoplay 会自己 play, 只有自定义的 autostart 手动调用 play
|
# autoplay 会自己 play, 只有自定义的 autostart 手动调用 play
|
||||||
if not Engine.is_editor_hint() and autostart:
|
if not Engine.is_editor_hint() and autostart:
|
||||||
@ -91,7 +97,7 @@ func _debug_mov_projection():
|
|||||||
var mov_config = animation_mov_dict[debug_mov_animation]
|
var mov_config = animation_mov_dict[debug_mov_animation]
|
||||||
# 展示 accumulated animation 的目标位置
|
# 展示 accumulated animation 的目标位置
|
||||||
debug_mov_onion_sprite2d.position.x = (
|
debug_mov_onion_sprite2d.position.x = (
|
||||||
mov_config.movement_x * (-1 if flip_h else 1) / scale.x
|
(mov_config.movement_x * (-1 if flip_h else 1) / scale.x) * sign(mov_config.velocity.x)
|
||||||
)
|
)
|
||||||
debug_mov_onion_sprite2d.texture = sprite_frames.get_frame_texture(debug_mov_animation, 0)
|
debug_mov_onion_sprite2d.texture = sprite_frames.get_frame_texture(debug_mov_animation, 0)
|
||||||
debug_mov_onion_sprite2d.flip_h = flip_h
|
debug_mov_onion_sprite2d.flip_h = flip_h
|
||||||
@ -183,19 +189,19 @@ func _physics_process(delta: float) -> void:
|
|||||||
position.x += diff_x
|
position.x += diff_x
|
||||||
# 检查是否切换 animation
|
# 检查是否切换 animation
|
||||||
if mov_x != 0.0 and mov_x_next_animation:
|
if mov_x != 0.0 and mov_x_next_animation:
|
||||||
accumulated_mov_x += diff_x
|
accumulated_mov_x += abs(diff_x)
|
||||||
if absf(accumulated_mov_x) >= absf(mov_x):
|
if accumulated_mov_x >= absf(mov_x):
|
||||||
if GlobalConfig.DEBUG:
|
if GlobalConfig.DEBUG:
|
||||||
print(
|
print(
|
||||||
"切换 animation:", mov_x_next_animation, " accumulated_mov_x=", accumulated_mov_x
|
"切换 animation:", mov_x_next_animation, " accumulated_mov_x=", accumulated_mov_x
|
||||||
)
|
)
|
||||||
play(mov_x_next_animation)
|
play(mov_x_next_animation)
|
||||||
if not velocity.y:
|
if velocity.y:
|
||||||
return
|
|
||||||
if flip_v:
|
if flip_v:
|
||||||
position.y -= velocity.y * delta
|
position.y -= velocity.y * delta
|
||||||
else:
|
else:
|
||||||
position.y += velocity.y * delta
|
position.y += velocity.y * delta
|
||||||
|
position_updated.emit(global_position)
|
||||||
|
|
||||||
|
|
||||||
# temporary set velocity
|
# temporary set velocity
|
||||||
|
Loading…
Reference in New Issue
Block a user