Modify the implementation of object (group) position in ortho map.

This commit is contained in:
zhangbin
2016-07-18 16:10:07 +08:00
parent 7501b4bd85
commit d9283a591f
4 changed files with 22 additions and 6 deletions
+1 -1
View File
@@ -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));
+18
View File
@@ -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 获取子对象的偏移位置。
+1 -1
View File
@@ -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
+2 -4
View File
@@ -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;