Skip to content

Commit ddc8b22

Browse files
committed
Merge pull request cocos2d#2766 from VisualSJ/develop-scale9Sprite
Fixed bug that is Scale9sprite cap error when no pre loading picture
2 parents 2ff3c4c + 2905045 commit ddc8b22

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

extensions/ccui/base-classes/UIScale9Sprite.js

+9
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,10 @@ ccui.Scale9Sprite = cc.Node.extend(/** @lends ccui.Scale9Sprite# */{
466466
this._textureLoaded = locLoaded;
467467
if(!locLoaded){
468468
texture.addEventListener("load", function(sender){
469+
if(this._capInsets.width === 0 && this._capInsets.height === 0){
470+
this._capInsets.width = sender._contentSize.width;
471+
this._capInsets.height = sender._contentSize.height;
472+
}
469473
// the texture is rotated on Canvas render mode, so isRotated always is false.
470474
var preferredSize = this._preferredSize;
471475
preferredSize = cc.size(preferredSize.width, preferredSize.height);
@@ -475,6 +479,11 @@ ccui.Scale9Sprite = cc.Node.extend(/** @lends ccui.Scale9Sprite# */{
475479
this._positionsAreDirty = true;
476480
this.dispatchEvent("load");
477481
}, this);
482+
}else{
483+
if(this._capInsets.width === 0 && this._capInsets.height === 0){
484+
capInsets.width = texture._contentSize.width;
485+
capInsets.height = texture._contentSize.height;
486+
}
478487
}
479488

480489
return this.initWithBatchNode(new cc.SpriteBatchNode(file, 9), rect, false, capInsets);

extensions/gui/control-extension/CCScale9Sprite.js

+9
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{
461461
this._textureLoaded = locLoaded;
462462
if(!locLoaded){
463463
texture.addEventListener("load", function(sender){
464+
if(this._capInsets.width === 0 && this._capInsets.height === 0){
465+
this._capInsets.width = sender._contentSize.width;
466+
this._capInsets.height = sender._contentSize.height;
467+
}
464468
// the texture is rotated on Canvas render mode, so isRotated always is false.
465469
var preferredSize = this._preferredSize;
466470
preferredSize = cc.size(preferredSize.width, preferredSize.height);
@@ -470,6 +474,11 @@ cc.Scale9Sprite = cc.Node.extend(/** @lends cc.Scale9Sprite# */{
470474
this._positionsAreDirty = true;
471475
this.dispatchEvent("load");
472476
}, this);
477+
}else{
478+
if(this._capInsets.width === 0 && this._capInsets.height === 0){
479+
capInsets.width = texture._contentSize.width;
480+
capInsets.height = texture._contentSize.height;
481+
}
473482
}
474483

475484
return this.initWithBatchNode(new cc.SpriteBatchNode(file, 9), rect, false, capInsets);

0 commit comments

Comments
 (0)