修复玩家移动时按e会平移的问题:action 相当于切换 idle
This commit is contained in:
parent
28d5d001d6
commit
4f50d8c668
@ -240,6 +240,10 @@ locale/fallback="zh"
|
|||||||
2d_physics/layer_7="npc"
|
2d_physics/layer_7="npc"
|
||||||
2d_physics/layer_8="little_game"
|
2d_physics/layer_8="little_game"
|
||||||
|
|
||||||
|
[rendering]
|
||||||
|
|
||||||
|
textures/canvas_textures/default_texture_filter=0
|
||||||
|
|
||||||
[statistics]
|
[statistics]
|
||||||
|
|
||||||
force_include=PackedStringArray()
|
force_include=PackedStringArray()
|
||||||
|
@ -34,14 +34,8 @@ signal animation_finished
|
|||||||
@export var player_movement_rect := Rect2(50, -500, 1400, 1000)
|
@export var player_movement_rect := Rect2(50, -500, 1400, 1000)
|
||||||
@export var velocity_ratio := 1.0
|
@export var velocity_ratio := 1.0
|
||||||
@export var running_locked := false
|
@export var running_locked := false
|
||||||
@export_enum("idle", "walking", "running") var current_status := 0:
|
@export_enum("idle", "walking", "running") var current_status := 0
|
||||||
set(val):
|
@export var facing_direction := Vector2(1.0, -1.0)
|
||||||
current_status = val
|
|
||||||
_play_animation()
|
|
||||||
@export var facing_direction := Vector2(1.0, -1.0):
|
|
||||||
set(val):
|
|
||||||
facing_direction = val
|
|
||||||
_play_animation()
|
|
||||||
|
|
||||||
@export var debug_freeze := 0:
|
@export var debug_freeze := 0:
|
||||||
set(val):
|
set(val):
|
||||||
@ -124,7 +118,7 @@ func _on_footstep_timer_timeout():
|
|||||||
|
|
||||||
|
|
||||||
# return whether the player status or facing direction has changed.
|
# 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 tmp_status = current_status
|
||||||
var new_facing_direction := facing_direction
|
var new_facing_direction := facing_direction
|
||||||
if direction.x:
|
if direction.x:
|
||||||
@ -141,8 +135,7 @@ func _check_status(direction) -> bool:
|
|||||||
if new_facing_direction != facing_direction or tmp_status != current_status:
|
if new_facing_direction != facing_direction or tmp_status != current_status:
|
||||||
facing_direction = new_facing_direction
|
facing_direction = new_facing_direction
|
||||||
current_status = tmp_status
|
current_status = tmp_status
|
||||||
return true
|
_play_animation()
|
||||||
return false
|
|
||||||
|
|
||||||
|
|
||||||
func _play_animation() -> void:
|
func _play_animation() -> void:
|
||||||
@ -261,6 +254,8 @@ func set_catty_light(enable := false):
|
|||||||
|
|
||||||
func player_action(action_code: int, auto_quit: bool):
|
func player_action(action_code: int, auto_quit: bool):
|
||||||
if current_animation_config.has(action_code):
|
if current_animation_config.has(action_code):
|
||||||
|
# 等价于播放另一种动画的 idle 状态
|
||||||
|
current_status = PlayerAnimationConfig.MOVEMENT_IDLE
|
||||||
# animation_name, scale, offset
|
# animation_name, scale, offset
|
||||||
var config = current_animation_config[action_code]
|
var config = current_animation_config[action_code]
|
||||||
var animation_l = config[0]
|
var animation_l = config[0]
|
||||||
@ -288,10 +283,7 @@ func _on_freeze_changed(count: int, is_add: bool):
|
|||||||
func _on_first_frozen() -> void:
|
func _on_first_frozen() -> void:
|
||||||
# reset status to idle or stay
|
# reset status to idle or stay
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
if (
|
if current_status != PlayerAnimationConfig.MOVEMENT_IDLE:
|
||||||
current_status == PlayerAnimationConfig.MOVEMENT_WALKING
|
|
||||||
or current_status == PlayerAnimationConfig.MOVEMENT_RUNNING
|
|
||||||
):
|
|
||||||
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)
|
print("walk_to:", global_pos, " from:", global_position)
|
||||||
# 不同距离下,行走时长略做自适应
|
# 不同距离下,行走时长略做自适应
|
||||||
var time_cost = absf(global_pos.distance_to(global_position) / 50.0)
|
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)
|
SceneManager.lock_player(0, 3, false)
|
||||||
|
var direction = facing_direction
|
||||||
if global_pos.x < global_position.x:
|
if global_pos.x < global_position.x:
|
||||||
facing_direction.x = -1.0
|
direction.x = -1.0
|
||||||
elif global_pos.x > global_position.x:
|
elif global_pos.x > global_position.x:
|
||||||
facing_direction.x = 1.0
|
direction.x = 1.0
|
||||||
_check_status(facing_direction)
|
_check_status(direction)
|
||||||
_play_animation()
|
_play_animation()
|
||||||
tween.tween_property(self, "global_position", global_pos, time_cost)
|
tween.tween_property(self, "global_position", global_pos, time_cost)
|
||||||
tween.tween_callback(_after_walk_to)
|
tween.tween_callback(_after_walk_to)
|
||||||
return tween
|
return tween
|
||||||
|
|
||||||
|
|
||||||
func _after_walk_to() -> void:
|
func _after_walk_to() -> void:
|
||||||
velocity = Vector2.ZERO
|
|
||||||
current_status = PlayerAnimationConfig.MOVEMENT_IDLE
|
|
||||||
_play_animation()
|
|
||||||
SceneManager.unlock_player()
|
SceneManager.unlock_player()
|
||||||
# _check_status(facing_direction)
|
_play_animation()
|
||||||
|
Loading…
Reference in New Issue
Block a user