
目前使用getPositionAt()方法获取的位置是不是错了,正确的应该是在下面一点

目前使用getPositionAt()方法获取的位置是不是错了,正确的应该是在下面一点
请问引擎版本是多少?
2.1.2
我手上没有合适的测试demo,你能把你的demo给我测试下么?
那为什么正数范围都是交错的,到了负数范围全都变成不交错了。。

宽高我已经改成0了 结果还是一样
_positionForHexAt (row, col) {
let tileWidth = this._mapTileSize.width;
let tileHeight = this._mapTileSize.height;
let cols = this._layerSize.height;
let offset = this._tileset.tileOffset;
let centerWidth = this.node.width / 2;
let centerHeight = this.node.height / 2;
let odd_even = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 1 : -1;
let x = 0, y = 0;
switch (this._staggerAxis) {
case cc.TiledMap.StaggerAxis.STAGGERAXIS_Y:
let diffX = 0;
let diffX1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 0 : tileWidth / 2;
if (col % 2 === 1) {
diffX = tileWidth / 2 * odd_even;
}
x = row * tileWidth + diffX + diffX1 + offset.x - centerWidth;
y = (cols - col - 1) * (tileHeight - (tileHeight - this._hexSideLength) / 2) - offset.y - centerHeight;
break;
case cc.TiledMap.StaggerAxis.STAGGERAXIS_X:
let diffY = 0;
let diffY1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? tileHeight / 2 : 0;
if (row % 2 === 1) {
diffY = tileHeight / 2 * -odd_even;
}
x = row * (tileWidth - (tileWidth - this._hexSideLength) / 2) + offset.x - centerWidth;
y = (cols - col - 1) * tileHeight + diffY + diffY1 - offset.y - centerHeight;
break;
}
return cc.v2(x, y);
},
解决了,这个函数奇数列判断改成
if (row % 2 !== 0) {
diffY = tileHeight / 2 * -odd_even;
}
