From ada1792e7134edc2a00a51e834b439e9a495aff5 Mon Sep 17 00:00:00 2001 From: zhakesi Date: Thu, 12 Jan 2023 13:59:56 +0800 Subject: [PATCH] fix tield layer hex contentSize wrong (#13817) --- cocos/tiledmap/tiled-layer.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cocos/tiledmap/tiled-layer.ts b/cocos/tiledmap/tiled-layer.ts index 061d6a6e61..595e577944 100644 --- a/cocos/tiledmap/tiled-layer.ts +++ b/cocos/tiledmap/tiled-layer.ts @@ -175,7 +175,7 @@ export class TiledLayer extends UIRenderer { get leftDownToCenterX () { return this._leftDownToCenterX; } get leftDownToCenterY () { return this._leftDownToCenterY; } - private _drawInfoList : RenderDrawInfo[] = []; + private _drawInfoList: RenderDrawInfo[] = []; private requestDrawInfo (idx: number) { if (!this._drawInfoList[idx]) { this._drawInfoList[idx] = new RenderDrawInfo(); @@ -1342,18 +1342,20 @@ export class TiledLayer extends UIRenderer { if (this._layerOrientation === Orientation.HEX) { let width = 0; let height = 0; + const tileWidth = maptw & ~1; + const tileHeight = mapth & ~1; this._odd_even = (this._staggerIndex === StaggerIndex.STAGGERINDEX_ODD) ? 1 : -1; if (this._staggerAxis === StaggerAxis.STAGGERAXIS_X) { - this._diffX1 = (maptw - this._hexSideLength) / 2; + this._diffX1 = (tileWidth - this._hexSideLength) / 2; this._diffY1 = 0; - height = mapth * (layerH + 0.5); - width = (maptw + this._hexSideLength) * Math.floor(layerW / 2) + maptw * (layerW % 2); + width = (this._diffX1 + this._hexSideLength) * layerW + this._diffX1; + height = (tileHeight * layerH) + tileHeight / 2; } else { this._diffX1 = 0; - this._diffY1 = (mapth - this._hexSideLength) / 2; - width = maptw * (layerW + 0.5); - height = (mapth + this._hexSideLength) * Math.floor(layerH / 2) + mapth * (layerH % 2); + this._diffY1 = (tileHeight - this._hexSideLength) / 2; + width = (tileWidth * layerW) + tileWidth / 2; + height = (this._diffY1 + this._hexSideLength) * layerH + this._diffY1; } this.node._uiProps.uiTransformComp!.setContentSize(width, height); } else if (this._layerOrientation === Orientation.ISO) {