Skip to content

Commit c1e5c0b

Browse files
committed
Merge pull request #1161 from dingpinglv/Iss2833_ReturnNewObjectForFunciton
Fixed #2833: refactor cc.Sprite's _rect to make its fault tolerance stronger
2 parents 3d4a89c + ea53e53 commit c1e5c0b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

cocos2d/sprite_nodes/CCSprite.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
317317
// Shared data
318318
//
319319
// texture
320-
_rect:cc.rect(0, 0, 0, 0), //Retangle of cc.Texture2D
320+
_rect:null, //Retangle of cc.Texture2D
321321
_rectRotated:false, //Whether the texture is rotated
322322

323323
// Offset Position (used by Zwoptex)
@@ -524,7 +524,10 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
524524
* @param {cc.Rect} rect
525525
*/
526526
setVertexRect:function (rect) {
527-
this._rect = rect;
527+
this._rect.x = rect.x;
528+
this._rect.y = rect.y;
529+
this._rect.width = rect.width;
530+
this._rect.height = rect.height;
528531
},
529532

530533
sortAllChildren:function () {
@@ -915,6 +918,7 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
915918
this._offsetPosition = cc.p(0, 0);
916919
this._unflippedOffsetPositionFromCenter = cc.p(0, 0);
917920
this._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST};
921+
this._rect = cc.rect(0,0,0,0);
918922

919923
this._quad = new cc.V3F_C4B_T2F_Quad();
920924
this._quadWebBuffer = cc.renderContext.createBuffer();
@@ -948,6 +952,7 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
948952
this._offsetPosition = cc.p(0, 0);
949953
this._unflippedOffsetPositionFromCenter = cc.p(0, 0);
950954
this._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST};
955+
this._rect = cc.rect(0,0,0,0);
951956

952957
this._newTextureWhenChangeColor = false;
953958
this._textureLoaded = true;
@@ -1159,7 +1164,12 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
11591164

11601165
if (!locTextureLoaded) {
11611166
this._rectRotated = rotated || false;
1162-
this._rect = rect;
1167+
if (!rect) {
1168+
this._rect.x = rect.x;
1169+
this._rect.y = rect.y;
1170+
this._rect.width = rect.width;
1171+
this._rect.height = rect.height;
1172+
}
11631173
texture.addLoadedEventListener(this._textureLoadedCallback, this);
11641174
return true;
11651175
}
@@ -1211,7 +1221,12 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
12111221

12121222
if (!locTextureLoaded) {
12131223
this._rectRotated = rotated || false;
1214-
this._rect = rect;
1224+
if (!rect) {
1225+
this._rect.x = rect.x;
1226+
this._rect.y = rect.y;
1227+
this._rect.width = rect.width;
1228+
this._rect.height = rect.height;
1229+
}
12151230
texture.addLoadedEventListener(this._textureLoadedCallback, this);
12161231
return true;
12171232
}

0 commit comments

Comments
 (0)