From f52d5736bf53d54f0cd994e2a78066ff0b90138e Mon Sep 17 00:00:00 2001 From: zhangbin Date: Mon, 11 Jul 2016 15:43:51 +0800 Subject: [PATCH 1/2] Convert the value of pos parameter from float to int. --- cocos2d/tilemap/CCSGTMXLayer.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index 64f1ca80e5..f84a23dcdd 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -339,7 +339,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ if (gid === 0) return tile; - var z = 0 | (pos.x + pos.y * this._layerSize.width); + var z = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); tile = this.getChildByTag(z); // tile not created yet. create it if (!tile) { @@ -351,7 +351,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ tile.setPosition(this.getPositionAt(pos)); tile.vertexZ = this._vertexZForPos(pos); tile.anchorX = 0; - tile.anchorY = 0; + tile.anchorY = 0; tile.opacity = this._opacity; var indexForZ = this._atlasIndexForExistantZ(z); @@ -380,7 +380,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ return null; } - var idx = 0 | (pos.x + pos.y * this._layerSize.width); + var idx = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); // Bits on the far end of the 32-bit global tile ID are used for tile flags var tile = this.tiles[idx]; @@ -407,7 +407,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ return null; } - var idx = 0 | (pos.x + pos.y * this._layerSize.width); + var idx = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); // Bits on the far end of the 32-bit global tile ID are used for tile flags var tile = this.tiles[idx]; @@ -435,6 +435,8 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ pos = posOrX; flags = flagsOrY; } + pos.x = Math.floor(pos.x); + pos.y = Math.floor(pos.y); if(pos.x >= this._layerSize.width || pos.y >= this._layerSize.height || pos.x < 0 || pos.y < 0) throw new Error("_ccsg.TMXLayer.setTileGID(): invalid position"); if(!this.tiles || !this._atlasIndexArray){ @@ -496,7 +498,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ if (gid !== 0) { if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) this._setNodeDirtyForCache(); - var z = 0 | (pos.x + pos.y * this._layerSize.width); + var z = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); var atlasIndex = this._atlasIndexForExistantZ(z); // remove tile from GID map this.tiles[z] = 0; @@ -538,6 +540,8 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ getPositionAt:function (pos, y) { if (y !== undefined) pos = cc.p(pos, y); + pos.x = Math.floor(pos.x); + pos.y = Math.floor(pos.y); var ret = cc.p(0,0); switch (this.layerOrientation) { case cc.TiledMap.Orientation.ORTHO: From 7c3eae9f2128ab6e6c5bb4e9f380a061dc756016 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Thu, 14 Jul 2016 11:23:46 +0800 Subject: [PATCH 2/2] Remove unused logic code. --- cocos2d/tilemap/CCSGTMXLayer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/tilemap/CCSGTMXLayer.js b/cocos2d/tilemap/CCSGTMXLayer.js index f84a23dcdd..7e3f5e5d50 100644 --- a/cocos2d/tilemap/CCSGTMXLayer.js +++ b/cocos2d/tilemap/CCSGTMXLayer.js @@ -339,7 +339,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ if (gid === 0) return tile; - var z = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); + var z = Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width; tile = this.getChildByTag(z); // tile not created yet. create it if (!tile) { @@ -380,7 +380,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ return null; } - var idx = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); + var idx = Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width; // Bits on the far end of the 32-bit global tile ID are used for tile flags var tile = this.tiles[idx]; @@ -407,7 +407,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ return null; } - var idx = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); + var idx = Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width; // Bits on the far end of the 32-bit global tile ID are used for tile flags var tile = this.tiles[idx]; @@ -498,7 +498,7 @@ _ccsg.TMXLayer = cc.SpriteBatchNode.extend(/** @lends _ccsg.TMXLayer# */{ if (gid !== 0) { if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) this._setNodeDirtyForCache(); - var z = 0 | (Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width); + var z = Math.floor(pos.x) + Math.floor(pos.y) * this._layerSize.width; var atlasIndex = this._atlasIndexForExistantZ(z); // remove tile from GID map this.tiles[z] = 0;