refactor(character): 使用整数坐标优化角色位置同步

- 将CharacterWorldPosition改为使用整数坐标,避免浮点精度问题
- 添加位置余数处理,确保移动平滑性
- 统一角色位置同步逻辑到SyncActorPositionFromWorld方法
- 修改地图移动检测使用整数坐标判断
This commit is contained in:
2026-04-05 11:42:39 +08:00
parent c4eefab70c
commit 2b0cfc6ce5
5 changed files with 122 additions and 37 deletions

View File

@@ -133,13 +133,18 @@ void CharacterObject::SetDirection(int direction) {
void CharacterObject::SetCharacterPosition(const Vec2& pos) {
motor_.SetGroundPosition(pos);
SetWorldPosition(motor_.position);
SyncActorPositionFromWorld();
}
void CharacterObject::SetWorldPosition(const CharacterWorldPosition& pos) {
motor_.position = pos;
SetPosition(pos.ToScreenPosition());
SetZOrder(static_cast<int>(pos.y));
motor_.SetWorldPosition(pos);
SyncActorPositionFromWorld();
}
void CharacterObject::SyncActorPositionFromWorld() {
const CharacterWorldPosition& worldPosition = motor_.position;
SetPosition(worldPosition.ToScreenPosition());
SetZOrder(worldPosition.y);
}
void CharacterObject::PushCommand(const CharacterCommand& command) {
@@ -240,7 +245,7 @@ void CharacterObject::OnUpdate(float deltaTime) {
currentIntent_ = commandBuffer_.BuildIntent();
stateMachine_.Update(*this, commandBuffer_, currentIntent_, deltaTime);
motor_.Update(deltaTime);
SetWorldPosition(motor_.position);
SyncActorPositionFromWorld();
SetFacing(motor_.facing);
}