修复玩家移动时按e会平移的问题:action 相当于切换 idle

This commit is contained in:
bbd_pc 2025-06-28 06:25:17 +08:00
parent 28d5d001d6
commit 4f50d8c668
2 changed files with 19 additions and 24 deletions

View File

@ -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()

View File

@ -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()