diff --git a/cocos2d/tilemap/CCSGTMXObject.js b/cocos2d/tilemap/CCSGTMXObject.js index 4a75010ebc..7185fe7910 100644 --- a/cocos2d/tilemap/CCSGTMXObject.js +++ b/cocos2d/tilemap/CCSGTMXObject.js @@ -69,7 +69,7 @@ _ccsg.TMXObjectImage = _ccsg.Sprite.extend(/** @lends cc.TMXObjectImage# */{ switch(mapOri) { case cc.TiledMap.Orientation.ORTHO: this.setAnchorPoint(cc.p(0, 0)); - this.setPosition(objInfo.x, objInfo.y + objInfo.height); + this.setPosition(objInfo.x, mapInfo._mapSize.height * mapInfo._tileSize.height - objInfo.y); break; case cc.TiledMap.Orientation.ISO: this.setAnchorPoint(cc.p(0.5, 0)); diff --git a/cocos2d/tilemap/CCSGTMXObjectGroup.js b/cocos2d/tilemap/CCSGTMXObjectGroup.js index d82f20d2da..7f4dae8ab1 100644 --- a/cocos2d/tilemap/CCSGTMXObjectGroup.js +++ b/cocos2d/tilemap/CCSGTMXObjectGroup.js @@ -56,11 +56,29 @@ _ccsg.TMXObjectGroup = _ccsg.Node.extend(/** @lends cc.TMXObjectGroup# */{ this._positionOffset = groupInfo.offset; this._mapInfo = mapInfo; this.properties = groupInfo.getProperties(); + this.setContentSize(mapInfo._tileSize.width * mapInfo._mapSize.width, mapInfo._tileSize.height * mapInfo._mapSize.height); + this._initPosWithMapInfo(groupInfo, mapInfo); this.setObjects(groupInfo._objects); this.setVisible(groupInfo.visible); }, + _initPosWithMapInfo: function (groupInfo, mapInfo) { + var mapOri = mapInfo.getOrientation(); + switch(mapOri) { + case cc.TiledMap.Orientation.ORTHO: + this.setAnchorPoint(cc.p(0, 0)); + this.setPosition(this._positionOffset.x, -this._positionOffset.y); + break; + case cc.TiledMap.Orientation.ISO: + break; + case cc.TiledMap.Orientation.HEX: + break; + default: + break; + } + }, + /** * !#en Offset position of child objects. * !#zh 获取子对象的偏移位置。 diff --git a/cocos2d/tilemap/CCSGTMXTiledMap.js b/cocos2d/tilemap/CCSGTMXTiledMap.js index f1e6b59fcd..07fb7d3016 100644 --- a/cocos2d/tilemap/CCSGTMXTiledMap.js +++ b/cocos2d/tilemap/CCSGTMXTiledMap.js @@ -369,7 +369,7 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{ var locChildren = this._children; for (var i = 0; i < locChildren.length; i++) { var group = locChildren[i]; - if (group && group instanceof _ccsg.TMXObjectGroup && group.groupName === layerName) + if (group && group instanceof _ccsg.TMXObjectGroup && group.groupName === groupName) return group; } // objectGroup not found diff --git a/cocos2d/tilemap/CCTMXXMLParser.js b/cocos2d/tilemap/CCTMXXMLParser.js index 2ca614d86f..2f5dfc9fd8 100644 --- a/cocos2d/tilemap/CCTMXXMLParser.js +++ b/cocos2d/tilemap/CCTMXXMLParser.js @@ -813,10 +813,8 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{ objectProp["width"] = parseFloat(selObj.getAttribute('width')) || 0; objectProp["height"] = parseFloat(selObj.getAttribute('height')) || 0; - objectProp["x"] = (((selObj.getAttribute('x') || 0) | 0) + objectGroup.offset.x) / getContentScaleFactor; - var y = (((selObj.getAttribute('y') || 0) | 0) + objectGroup.offset.y) / getContentScaleFactor; - // Correct y position. (Tiled uses Flipped, cocos2d uses Standard) - objectProp["y"] = (parseInt(this.getMapSize().height * this.getTileSize().height) - y - objectProp["height"]) / cc.director.getContentScaleFactor(); + objectProp["x"] = (selObj.getAttribute('x') || 0) / getContentScaleFactor; + objectProp["y"] = (selObj.getAttribute('y') || 0) / getContentScaleFactor; objectProp["rotation"] = parseInt(selObj.getAttribute('rotation')) || 0;