fix: 视角同步问题 & delegateTicker执行时机

This commit is contained in:
unanmed 2024-12-23 21:07:00 +08:00
parent 297b67da5b
commit e5e0458891
2 changed files with 25 additions and 33 deletions

View File

@ -76,6 +76,7 @@ import './render/index';
import * as RenderUtils from './render/utils';
import '@/module';
import { MotaOffscreenCanvas2D } from './fx/canvas2d';
import { TextboxStore } from './render/index';
// ----- 类注册
Mota.register('class', 'AudioPlayer', AudioPlayer);
@ -163,7 +164,8 @@ Mota.register('module', 'Render', {
LayerGroupFloorBinder,
Camera,
MotaOffscreenCanvas2D,
Utils: RenderUtils
Utils: RenderUtils,
TextboxStore
});
Mota.register('module', 'Action', {
HeroKeyMover

View File

@ -67,8 +67,10 @@ export class FloorViewport implements ILayerGroupRenderExtends {
const halfHeight = core._PY_ / 2;
const cell = this.group.cellSize;
const half = cell / 2;
this.nx = -(nx - halfWidth + half) / this.group.cellSize;
this.ny = -(ny - halfHeight + half) / this.group.cellSize;
this.applyPosition(
-(nx - halfWidth + half) / this.group.cellSize,
-(ny - halfHeight + half) / this.group.cellSize
);
this.mutateTo(x, y);
}
@ -116,8 +118,7 @@ export class FloorViewport implements ILayerGroupRenderExtends {
if (!this.enabled) return;
const { x: nx, y: ny } = this.getBoundedPosition(x, y);
this.group.removeTicker(this.transition, false);
this.nx = nx;
this.ny = ny;
this.applyPosition(nx, ny);
}
/**
@ -198,8 +199,7 @@ export class FloorViewport implements ILayerGroupRenderExtends {
const { x, y } = this.hero!.renderable;
const { x: nx, y: ny } = this.getBoundedPosition(x, y);
this.nx = nx;
this.ny = ny;
this.applyPosition(nx, ny);
if (ending) {
if (this.ox === xTarget && this.oy == yTarget) {
@ -264,41 +264,32 @@ export class FloorViewport implements ILayerGroupRenderExtends {
const progress = fn((now - start) / time);
const tx = dx * progress;
const ty = dy * progress;
this.nx = tx + sx;
this.ny = ty + sy;
this.applyPosition(tx + sx, ty + sy);
},
time,
() => {
this.nx = x;
this.ny = y;
this.applyPosition(x, y);
this.inTransition = false;
}
);
}
private create() {
let nx = this.nx;
let ny = this.ny;
private applyPosition(x: number, y: number) {
if (!this.enabled) return;
if (x === this.nx && y === this.ny) return;
const halfWidth = core._PX_ / 2;
const halfHeight = core._PY_ / 2;
this.delegation = this.group.delegateTicker(() => {
if (!this.enabled) return;
if (this.nx === nx && this.ny === ny) {
return;
}
const cell = this.group.cellSize;
const half = cell / 2;
nx = this.nx;
ny = this.ny;
const { x: bx, y: by } = this.getBoundedPosition(nx, ny);
this.nx = x;
this.ny = y;
const { x: bx, y: by } = this.getBoundedPosition(x, y);
const rx = bx * cell - halfWidth + half;
const ry = by * cell - halfHeight + half;
core.bigmap.offsetX = rx;
core.bigmap.offsetY = ry;
this.group.camera.setTranslate(-rx, -ry);
this.group.update(this.group);
});
// this.createMoving();
}
private checkDependency() {
@ -319,7 +310,6 @@ export class FloorViewport implements ILayerGroupRenderExtends {
awake(group: LayerGroup): void {
this.group = group;
this.create();
adapter.add(this);
}