|
@@ -112,15 +112,7 @@ export default class UEGridMap extends UEBase {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /** 根据索引获取实际像素坐标 */
|
|
|
- private GetPosByIdx(i: number, j: number): cc.Vec3 {
|
|
|
- const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
|
|
|
- const startY = (GridConstant.COL * GridConstant.CELL_WIDTH) / 2;
|
|
|
- return cc.v3(
|
|
|
- startX + j * GridConstant.CELL_WIDTH + GridConstant.CELL_WIDTH / 2,
|
|
|
- startY - i * GridConstant.CELL_WIDTH - GridConstant.CELL_WIDTH / 2
|
|
|
- )
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/** 创建格子 */
|
|
|
private CreateCell(i: number, j: number) {
|
|
@@ -128,7 +120,7 @@ export default class UEGridMap extends UEBase {
|
|
|
this.cellLayer.addChild(cell.node);
|
|
|
cell.node.width = GridConstant.CELL_WIDTH;
|
|
|
cell.node.height = GridConstant.CELL_WIDTH;
|
|
|
- let pos = this.GetPosByIdx(i, j);
|
|
|
+ let pos = GameDataCenter.gridMap.GetPosByVec(i, j);
|
|
|
cell.node.setPosition(pos);
|
|
|
return cell;
|
|
|
}
|
|
@@ -139,7 +131,7 @@ export default class UEGridMap extends UEBase {
|
|
|
this.cubeLayer.addChild(cube.node);
|
|
|
cube.node.width = GridConstant.CELL_WIDTH;
|
|
|
cube.node.height = GridConstant.CELL_WIDTH;
|
|
|
- let pos = this.GetPosByIdx(i, j);
|
|
|
+ let pos = GameDataCenter.gridMap.GetPosByVec(i, j);
|
|
|
cube.node.setPosition(pos);
|
|
|
return cube;
|
|
|
}
|
|
@@ -285,7 +277,7 @@ export default class UEGridMap extends UEBase {
|
|
|
|
|
|
// 计算起点和终点
|
|
|
const startWorldPos = mergeCube.node.getPosition();
|
|
|
- const endWorldPos = this.GetPosByIdx(targetPos.y, targetPos.x);
|
|
|
+ const endWorldPos = GameDataCenter.gridMap.GetPosByVec(targetPos.y, targetPos.x);
|
|
|
|
|
|
// 计算方向向量和总距离
|
|
|
const moveVec = cc.v2(endWorldPos.x - startWorldPos.x, endWorldPos.y - startWorldPos.y);
|