修改了很多
This commit is contained in:
@@ -24,6 +24,9 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
const shouldStop = enemiesStop;
|
||||
view.is_atking = shouldStop;
|
||||
|
||||
// 更新渲染层级
|
||||
this.updateRenderOrder(e);
|
||||
|
||||
// 同步状态
|
||||
if (!shouldStop) {
|
||||
if(view.is_stop||view.is_dead) return //停止移动或者死亡不移动
|
||||
@@ -134,4 +137,29 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 更新渲染层级 */
|
||||
private updateRenderOrder(entity: ecs.Entity) {
|
||||
const current = entity.get(HeroViewComp);
|
||||
|
||||
// 查找所有单位
|
||||
const allUnits = ecs.query(ecs.allOf(HeroViewComp)).filter(e => {
|
||||
const other = e.get(HeroViewComp);
|
||||
return other.fac === current.fac; // 按阵营分组
|
||||
});
|
||||
|
||||
// 按y坐标从大到小排序(y坐标越小显示在上层)
|
||||
const sortedUnits = allUnits.sort((a, b) => {
|
||||
const posA = a.get(HeroViewComp).node.position.y;
|
||||
const posB = b.get(HeroViewComp).node.position.y;
|
||||
return posB - posA; // 修改排序顺序
|
||||
});
|
||||
|
||||
// 设置渲染顺序
|
||||
|
||||
// 根据y坐标设置层级,y坐标越小的显示在上层
|
||||
const index = sortedUnits.findIndex(e => e === entity);
|
||||
current.node.setSiblingIndex(index);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user