Skip to content

Commit

Permalink
Merge pull request cocos#515 from pandamicro/v1.0
Browse files Browse the repository at this point in the history
Fix Rect width exceeds maximum margin issue in JSB
  • Loading branch information
pandamicro committed Mar 21, 2016
2 parents d41b71d + 5934f04 commit 6c0626f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions jsb/jsb-tex-sprite-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ cc.SpriteFrame.prototype._deserialize = function (data, handle) {
cc.SpriteFrame.prototype._checkRect = function (texture) {
var rect = this.getRect();
var maxX = rect.x, maxY = rect.y;
if (this._rotated) {
if (this.isRotated()) {
maxX += rect.height;
maxY += rect.width;
}
Expand All @@ -166,17 +166,25 @@ cc.SpriteFrame.prototype.getTexture = function () {
cc.js.set(cc.SpriteFrame.prototype, '_textureFilenameSetter', function (url) {
this._textureFilename = url;
if (url) {
// texture will be init in getTexture()
var texture = this.getTexture();
if (this.textureLoaded()) {
cc.textureCache.addImage(url, function (texture) {
if (this.getTexture() !== texture) {
this.setTexture(texture);
var w = texture.getPixelWidth(), h = texture.getPixelHeight();
if (this.getRect().width === 0) {
this.setRect(cc.rect(0, 0, w, h));
}
if (this.getOriginalSize().width === 0) {
this.setOriginalSize(cc.size(w, h));
}
if (this.getOffset().width === 0) {
this.setOffset(cc.v2(0, 0));
}

this._texture = texture;
}
this._checkRect(texture);
this.emit('load');
}
else {
// register event in setTexture()
this._texture = null;
this.setTexture(texture);
}
}, this);
}
});

Expand Down

0 comments on commit 6c0626f

Please sign in to comment.