From f09704f7da24064f84e8f55af371aafbad701c32 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 19 Oct 2024 18:35:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=92=9E=E5=A2=99=E4=B8=8A=E6=97=B6?= =?UTF-8?q?=E5=B9=B3=E6=BB=91=E8=A7=86=E8=A7=92=E5=8D=A1=E4=BD=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/render/preset/viewport.ts | 12 +++++++----- src/game/state/move.ts | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/render/preset/viewport.ts b/src/core/render/preset/viewport.ts index 534e725..f55a542 100644 --- a/src/core/render/preset/viewport.ts +++ b/src/core/render/preset/viewport.ts @@ -163,8 +163,8 @@ export class FloorViewport implements ILayerGroupRenderExtends { const setTargetX = (x: number, time: number) => { if (x === xTarget) return; xTarget = x; - xStart = this.ox; xStartTime = time; + xStart = this.ox; }; const setTargetY = (y: number, time: number) => { if (y === yTarget) return; @@ -186,8 +186,8 @@ export class FloorViewport implements ILayerGroupRenderExtends { if (!ending) { const dir = this.hero.stepDir; const { x, y } = core.utils.scan2[dir]; - if (x !== 0) setTargetX(-x * this.maxOffset, now); - if (y !== 0) setTargetY(-y * this.maxOffset, now); + setTargetX(-x * this.maxOffset, now); + setTargetY(-y * this.maxOffset, now); } if (!this.hero.renderable) return; @@ -202,7 +202,8 @@ export class FloorViewport implements ILayerGroupRenderExtends { } } if (this.ox !== xTarget) { - const progress = (now - xStartTime) / transitionTime; + const time = transitionTime * Math.abs(xStart - xTarget); + const progress = (now - xStartTime) / time; if (progress > 1) { this.ox = xTarget; } else { @@ -211,7 +212,8 @@ export class FloorViewport implements ILayerGroupRenderExtends { } } if (this.oy !== yTarget) { - const progress = (now - yStartTime) / transitionTime; + const time = transitionTime * Math.abs(yStart - yTarget); + const progress = (now - yStartTime) / time; if (progress > 1) { this.oy = yTarget; } else { diff --git a/src/game/state/move.ts b/src/game/state/move.ts index 2d0f1bc..0a461fc 100644 --- a/src/game/state/move.ts +++ b/src/game/state/move.ts @@ -484,7 +484,12 @@ export class HeroMover extends ObjectMoverBase { const viewport = HeroMover.viewport; if (!adapter || !viewport) return; await adapter.all('readyMove'); - viewport.sync('startMove'); + // 这里要检查前面那一格能不能走,不能走则不触发平滑视角,以避免撞墙上视角卡住 + const { x, y } = core.status.hero.loc; + const data = this.checkCanMove(x, y, toDir(this.faceDir)); + if (data.canMove && !data.noPass) { + viewport.sync('startMove'); + } adapter.sync('startAnimate'); }