Skip to content

Commit

Permalink
Solve the errors in logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbin committed Jul 25, 2016
1 parent 4dd2557 commit a6eeb67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
34 changes: 22 additions & 12 deletions cocos2d/tilemap/CCSGTMXObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,12 @@ _ccsg.TMXObjectImage = _ccsg.Sprite.extend(/** @lends cc.TMXObjectImage# */{
this.setVisible(objInfo.visible);

// init the image
var rect = useTileset.rectForGID(this.gid);
var texture = cc.textureCache.addImage(cc.path._normalize(useTileset.sourceImage));
var initRet = this.initWithTexture(texture, rect);
if (!initRet) {
return false;
}
var texture = cc.textureCache.addImage(cc.path._normalize(tileset.sourceImage));
this._initWithTileset(objInfo, texture, useTileset);

// init the position & anchor point with map info
this._initPosWithMapInfo(objInfo, mapInfo);

// set scale
this.setScaleX(objInfo.width / rect.size.width);
this.setScaleY(objInfo.height / rect.size.height);

// set rotation
this.setRotation(objInfo.rotation);

Expand All @@ -65,6 +57,24 @@ _ccsg.TMXObjectImage = _ccsg.Sprite.extend(/** @lends cc.TMXObjectImage# */{
return true;
},

_initWithTileset: function(objInfo, texture, tileset) {
if (!texture.isLoaded()) {
texture.once('load', function () {
this._initWithTileset(objInfo, texture, tileset);
}, this);
return;
}

tileset.imageSize.width = texture.width;
tileset.imageSize.height = texture.height;
var rect = tileset.rectForGID(this.gid);
this.initWithTexture(texture, rect);

// set scale
this.setScaleX(objInfo.width / rect.size.width);
this.setScaleY(objInfo.height / rect.size.height);
},

_initPosWithMapInfo: function (objInfo, mapInfo) {
var mapOri = mapInfo.getOrientation();
switch(mapOri) {
Expand Down Expand Up @@ -150,5 +160,5 @@ cc.TMXObject = {
}
};

cc.js.mixin(_ccsg.TMXObjectImage.prototype, cc.TMXObjectHelper);
cc.js.mixin(_ccsg.TMXObjectShape.prototype, cc.TMXObjectHelper);
cc.js.mixin(_ccsg.TMXObjectImage.prototype, cc.TMXObject);
cc.js.mixin(_ccsg.TMXObjectShape.prototype, cc.TMXObject);
4 changes: 2 additions & 2 deletions cocos2d/tilemap/CCSGTMXObjectGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ _ccsg.TMXObjectGroup = _ccsg.Node.extend(/** @lends cc.TMXObjectGroup# */{
* @method getGroupName
* @return {String}
* @example
* var groupName = tMXObjectGroup.getGroupName;
* var groupName = tMXObjectGroup.getGroupName();
*/
getGroupName:function () {
return this.groupName.toString();
return this.groupName;
},

/**
Expand Down
1 change: 0 additions & 1 deletion extends.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require('./cocos2d/tilemap/CCTiledMapAsset');
if (!(CC_EDITOR && Editor.isMainProcess)) {
require('./cocos2d/tilemap/CCTiledMap');
require('./cocos2d/tilemap/CCTiledLayer');
require('./cocos2d/tilemap/CCTiledObject');
require('./cocos2d/tilemap/CCTiledObjectGroup');
}

Expand Down

0 comments on commit a6eeb67

Please sign in to comment.