Skip to content

Fixed #2833: refactor cc.Sprite's _rect to make its fault tolerance stronger #1161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions cocos2d/sprite_nodes/CCSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
// Shared data
//
// texture
_rect:cc.rect(0, 0, 0, 0), //Retangle of cc.Texture2D
_rect:null, //Retangle of cc.Texture2D
_rectRotated:false, //Whether the texture is rotated

// Offset Position (used by Zwoptex)
Expand Down Expand Up @@ -524,7 +524,10 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{
* @param {cc.Rect} rect
*/
setVertexRect:function (rect) {
this._rect = rect;
this._rect.x = rect.x;
this._rect.y = rect.y;
this._rect.width = rect.width;
this._rect.height = rect.height;
},

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

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

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

if (!locTextureLoaded) {
this._rectRotated = rotated || false;
this._rect = rect;
if (!rect) {
this._rect.x = rect.x;
this._rect.y = rect.y;
this._rect.width = rect.width;
this._rect.height = rect.height;
}
texture.addLoadedEventListener(this._textureLoadedCallback, this);
return true;
}
Expand Down Expand Up @@ -1211,7 +1221,12 @@ cc.Sprite = cc.NodeRGBA.extend(/** @lends cc.Sprite# */{

if (!locTextureLoaded) {
this._rectRotated = rotated || false;
this._rect = rect;
if (!rect) {
this._rect.x = rect.x;
this._rect.y = rect.y;
this._rect.width = rect.width;
this._rect.height = rect.height;
}
texture.addLoadedEventListener(this._textureLoadedCallback, this);
return true;
}
Expand Down