From 4f50d8c66832a4c30d9d26ec41afaa24f3326976 Mon Sep 17 00:00:00 2001 From: bbd_pc Date: Sat, 28 Jun 2025 06:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8E=A9=E5=AE=B6=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E6=8C=89e=E4=BC=9A=E5=B9=B3=E7=A7=BB?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9Aaction=20=E7=9B=B8=E5=BD=93?= =?UTF-8?q?=E4=BA=8E=E5=88=87=E6=8D=A2=20idle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.godot | 4 ++++ scene/character/main_player.gd | 39 +++++++++++++--------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/project.godot b/project.godot index 81a740e2..5060e1de 100644 --- a/project.godot +++ b/project.godot @@ -240,6 +240,10 @@ locale/fallback="zh" 2d_physics/layer_7="npc" 2d_physics/layer_8="little_game" +[rendering] + +textures/canvas_textures/default_texture_filter=0 + [statistics] force_include=PackedStringArray() diff --git a/scene/character/main_player.gd b/scene/character/main_player.gd index 280c2dc0..610ef0f3 100644 --- a/scene/character/main_player.gd +++ b/scene/character/main_player.gd @@ -34,14 +34,8 @@ signal animation_finished @export var player_movement_rect := Rect2(50, -500, 1400, 1000) @export var velocity_ratio := 1.0 @export var running_locked := false -@export_enum("idle", "walking", "running") var current_status := 0: - set(val): - current_status = val - _play_animation() -@export var facing_direction := Vector2(1.0, -1.0): - set(val): - facing_direction = val - _play_animation() +@export_enum("idle", "walking", "running") var current_status := 0 +@export var facing_direction := Vector2(1.0, -1.0) @export var debug_freeze := 0: set(val): @@ -124,7 +118,7 @@ func _on_footstep_timer_timeout(): # return whether the player status or facing direction has changed. -func _check_status(direction) -> bool: +func _check_status(direction) -> void: var tmp_status = current_status var new_facing_direction := facing_direction if direction.x: @@ -141,8 +135,7 @@ func _check_status(direction) -> bool: if new_facing_direction != facing_direction or tmp_status != current_status: facing_direction = new_facing_direction current_status = tmp_status - return true - return false + _play_animation() func _play_animation() -> void: @@ -261,6 +254,8 @@ func set_catty_light(enable := false): func player_action(action_code: int, auto_quit: bool): if current_animation_config.has(action_code): + # 等价于播放另一种动画的 idle 状态 + current_status = PlayerAnimationConfig.MOVEMENT_IDLE # animation_name, scale, offset var config = current_animation_config[action_code] var animation_l = config[0] @@ -288,10 +283,7 @@ func _on_freeze_changed(count: int, is_add: bool): func _on_first_frozen() -> void: # reset status to idle or stay velocity = Vector2.ZERO - if ( - current_status == PlayerAnimationConfig.MOVEMENT_WALKING - or current_status == PlayerAnimationConfig.MOVEMENT_RUNNING - ): + if current_status != PlayerAnimationConfig.MOVEMENT_IDLE: current_status = PlayerAnimationConfig.MOVEMENT_IDLE @@ -493,22 +485,21 @@ func walk_to(global_pos: Vector2) -> Tween: print("walk_to:", global_pos, " from:", global_position) # 不同距离下,行走时长略做自适应 var time_cost = absf(global_pos.distance_to(global_position) / 50.0) - if time_cost > 0: + # 忽略过小的位移 + if time_cost >= 0.05: SceneManager.lock_player(0, 3, false) + var direction = facing_direction if global_pos.x < global_position.x: - facing_direction.x = -1.0 + direction.x = -1.0 elif global_pos.x > global_position.x: - facing_direction.x = 1.0 - _check_status(facing_direction) + direction.x = 1.0 + _check_status(direction) _play_animation() tween.tween_property(self, "global_position", global_pos, time_cost) - tween.tween_callback(_after_walk_to) + tween.tween_callback(_after_walk_to) return tween func _after_walk_to() -> void: - velocity = Vector2.ZERO - current_status = PlayerAnimationConfig.MOVEMENT_IDLE - _play_animation() SceneManager.unlock_player() - # _check_status(facing_direction) + _play_animation()