diff --git a/addons/property-inspector/pro_animation_sprite2d/pro_animated_sprite.gd b/addons/property-inspector/pro_animation_sprite2d/pro_animated_sprite.gd index 417b3af2..80baedb6 100644 --- a/addons/property-inspector/pro_animation_sprite2d/pro_animated_sprite.gd +++ b/addons/property-inspector/pro_animation_sprite2d/pro_animated_sprite.gd @@ -1,6 +1,8 @@ @tool class_name ProAnimatedSprite2D extends AnimatedSprite2D +signal position_updated(global_pos: Vector2) + @export var autostart := true @export var action_configs: Array[Dictionary] = [] @export var move_configs: Array[Dictionary] = [] @@ -46,7 +48,7 @@ static func new_action_config() -> Dictionary: return ACTION_CONFIG.duplicate() -@onready var debug_mov_onion_sprite2d = $DebugMovOnionSkinSprite2D as Sprite2D +var debug_mov_onion_sprite2d: Sprite2D # 从 intro 到 next 的配置信息 var auto_checkout_dict = { @@ -73,12 +75,16 @@ func _ready() -> void: animation_finished.connect(_on_animation_finished) animation_looped.connect(_on_animation_finished) # 处理 debug_mov_onion_sprite2d + debug_mov_onion_sprite2d = get_node_or_null("DebugMovOnionSkinSprite2D") if Engine.is_editor_hint(): - # stop() - # frame = 0 + if not debug_mov_onion_sprite2d: + 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_mov_projection() - else: + elif debug_mov_onion_sprite2d: debug_mov_onion_sprite2d.queue_free() # autoplay 会自己 play, 只有自定义的 autostart 手动调用 play 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] # 展示 accumulated animation 的目标位置 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.flip_h = flip_h @@ -183,19 +189,19 @@ func _physics_process(delta: float) -> void: position.x += diff_x # 检查是否切换 animation if mov_x != 0.0 and mov_x_next_animation: - accumulated_mov_x += diff_x - if absf(accumulated_mov_x) >= absf(mov_x): + accumulated_mov_x += abs(diff_x) + if accumulated_mov_x >= absf(mov_x): if GlobalConfig.DEBUG: print( "切换 animation:", mov_x_next_animation, " accumulated_mov_x=", accumulated_mov_x ) play(mov_x_next_animation) - if not velocity.y: - return - if flip_v: - position.y -= velocity.y * delta - else: - position.y += velocity.y * delta + if velocity.y: + if flip_v: + position.y -= velocity.y * delta + else: + position.y += velocity.y * delta + position_updated.emit(global_position) # temporary set velocity