From 3f4f0f21916b643ef6cfb7b30f882a75c8d13eef Mon Sep 17 00:00:00 2001 From: zhangbin Date: Thu, 21 Jul 2016 09:35:48 +0800 Subject: [PATCH] Solve the error content size of hex tiled map. --- cocos2d/tilemap/CCSGTMXLayer.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 701a866f18..940b8aa0f7 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -222,8 +222,20 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{ // Parse cocos2d properties this._parseInternalProperties(); - this.setContentSize(this._layerSize.width * this._mapTileSize.width, - this._layerSize.height * this._mapTileSize.height); + if (this.layerOrientation === cc.TiledMap.Orientation.HEX) { + var width = 0, height = 0; + if (this._staggerAxis === cc.TiledMap.StaggerAxis.STAGGERAXIS_X) { + height = mapInfo._tileSize.height * (this._layerSize.height + 0.5); + width = (mapInfo._tileSize.width + this._hexSideLength) * Math.floor(this._layerSize.width / 2) + mapInfo._tileSize.width * (this._layerSize.width % 2); + } else { + width = mapInfo._tileSize.width * (this._layerSize.width + 0.5); + height = (mapInfo._tileSize.height + this._hexSideLength) * Math.floor(this._layerSize.height / 2) + mapInfo._tileSize.height * (this._layerSize.height % 2); + } + this.setContentSize(width, height); + } else { + this.setContentSize(this._layerSize.width * this._mapTileSize.width, + this._layerSize.height * this._mapTileSize.height); + } this._useAutomaticVertexZ = false; this._vertexZvalue = 0; return true;