From baffa635522dc1f227dccbc2043efee5bc69434a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 26 Oct 2017 12:19:25 +0200 Subject: [PATCH] tilemap: Fixed calculation of tileset rows/columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The margin should only be subtracted once, since it’s irrelevant whether the margin exists also at the bottom or the right side of the image. With this change it matches the behavior of Tiled. --- cocos2d/tilemap/CCTMXLayer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/tilemap/CCTMXLayer.js b/cocos2d/tilemap/CCTMXLayer.js index e78c8d082f..754f8beede 100644 --- a/cocos2d/tilemap/CCTMXLayer.js +++ b/cocos2d/tilemap/CCTMXLayer.js @@ -129,8 +129,8 @@ cc.TMXLayer = cc.SpriteBatchNode.extend(/** @lends cc.TMXLayer# */{ spacing = tileset.spacing, margin = tileset.margin, - cols = Math.floor((imageW - margin*2 + spacing) / (tw + spacing)), - rows = Math.floor((imageH - margin*2 + spacing) / (th + spacing)), + cols = Math.floor((imageW - margin + spacing) / (tw + spacing)), + rows = Math.floor((imageH - margin + spacing) / (th + spacing)), count = rows * cols, gid = tileset.firstGid,