Merge branch 'card' of git.eoxnet.com:pan/pixelheros into card
This commit is contained in:
@@ -263,7 +263,10 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
|
|
||||||
private moveToSlot(view: HeroViewComp, move: MoveComp, model: HeroAttrsComp, targetX: number) {
|
private moveToSlot(view: HeroViewComp, move: MoveComp, model: HeroAttrsComp, targetX: number) {
|
||||||
const currentX = view.node.position.x;
|
const currentX = view.node.position.x;
|
||||||
if (Math.abs(currentX - targetX) <= 2) {
|
const currentY = view.node.position.y;
|
||||||
|
|
||||||
|
// 当 X 和 Y 都到达目标时,才算真正到达
|
||||||
|
if (Math.abs(currentX - targetX) <= 2 && Math.abs(currentY - move.baseY) <= 2) {
|
||||||
view.node.setPosition(targetX, move.baseY, 0);
|
view.node.setPosition(targetX, move.baseY, 0);
|
||||||
view.status_change("idle");
|
view.status_change("idle");
|
||||||
return;
|
return;
|
||||||
@@ -283,14 +286,25 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
const moveMinX = Math.min(cfg.moveBackX, cfg.moveFrontX);
|
const moveMinX = Math.min(cfg.moveBackX, cfg.moveFrontX);
|
||||||
const moveMaxX = Math.max(cfg.moveBackX, cfg.moveFrontX);
|
const moveMaxX = Math.max(cfg.moveBackX, cfg.moveFrontX);
|
||||||
const currentX = view.node.position.x;
|
const currentX = view.node.position.x;
|
||||||
|
const currentY = view.node.position.y;
|
||||||
|
|
||||||
const delta = speed * this.dt * direction;
|
const delta = speed * this.dt * direction;
|
||||||
let newX = view.node.position.x + delta;
|
let newX = view.node.position.x + delta;
|
||||||
if (currentX < moveMinX && direction < 0) {
|
if (currentX < moveMinX && direction < 0) {
|
||||||
|
// X 轴到底了,如果 Y 轴还在换路,继续维持 move 状态
|
||||||
|
if (Math.abs(currentY - move.baseY) > 2) {
|
||||||
|
view.status_change("move");
|
||||||
|
} else {
|
||||||
view.status_change("idle");
|
view.status_change("idle");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (currentX > moveMaxX && direction > 0) {
|
if (currentX > moveMaxX && direction > 0) {
|
||||||
|
if (Math.abs(currentY - move.baseY) > 2) {
|
||||||
|
view.status_change("move");
|
||||||
|
} else {
|
||||||
view.status_change("idle");
|
view.status_change("idle");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newX = Math.max(moveMinX, Math.min(moveMaxX, newX));
|
newX = Math.max(moveMinX, Math.min(moveMaxX, newX));
|
||||||
@@ -299,10 +313,15 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
newX = direction > 0 ? Math.min(newX, stopAtX) : Math.max(newX, stopAtX);
|
newX = direction > 0 ? Math.min(newX, stopAtX) : Math.max(newX, stopAtX);
|
||||||
}
|
}
|
||||||
if (Math.abs(newX - currentX) < 0.01) {
|
if (Math.abs(newX - currentX) < 0.01) {
|
||||||
|
// X轴虽然没变化,但如果Y轴还在移动,依然是move状态
|
||||||
|
if (Math.abs(currentY - move.baseY) > 2) {
|
||||||
|
view.status_change("move");
|
||||||
|
} else {
|
||||||
view.status_change("idle");
|
view.status_change("idle");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
view.node.setPosition(newX, move.baseY, 0);
|
view.node.setPosition(newX, view.node.position.y, 0); // 注意:这里只更新 X,Y 在外部平滑逻辑更新
|
||||||
view.status_change("move");
|
view.status_change("move");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user