Skip to content

Commit e8dc4c3

Browse files
author
SeanLin
committed
Merge pull request #751 from linshun/iss1665_v2.1.1
add timmjd's commit
2 parents d4dee2b + ba1b336 commit e8dc4c3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

cocos2d/sprite_nodes/CCSprite.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
244244
_texture:null,
245245
_originalTexture:null,
246246
_color:null,
247+
_colorized:false,
247248
//
248249
// Shared data
249250
//
@@ -912,12 +913,18 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
912913
this._rect.size.width = this._texture.width;
913914
this._rect.size.height = this._texture.height;
914915
context.drawImage(this._texture, posX, -(posY + this._texture.height));
915-
} else {
916+
} else if(this._colorized) {
916917
context.drawImage(this._texture,
917918
0, 0,
918919
this._rect.size.width, this._rect.size.height,
919920
posX, -(posY + this._rect.size.height),
920921
this._rect.size.width, this._rect.size.height);
922+
} else {
923+
context.drawImage(this._texture,
924+
this._rect.origin.x, this._rect.origin.y,
925+
this._rect.size.width, this._rect.size.height,
926+
posX, -(posY + this._rect.size.height),
927+
this._rect.size.width, this._rect.size.height);
921928
}
922929
}
923930
} else {
@@ -1440,6 +1447,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
14401447
if (cc.renderContextType === cc.CANVAS) {
14411448
var cacheTextureForColor = cc.TextureCache.getInstance().getTextureColors(this._originalTexture);
14421449
if (cacheTextureForColor) {
1450+
this._colorized = true;
14431451
//generate color texture cache
14441452
if (this._texture instanceof HTMLCanvasElement && !this._rectRotated) {
14451453
cc.generateTintImage(this.getTexture(), cacheTextureForColor, this._color, this.getTextureRect(), this._texture);

extensions/GUI/CCControlExtension/CCScale9Sprite.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ cc.Scale9Sprite = cc.Node.extend({
237237
initWithBatchNode:function (batchNode, rect, unused, capInsets) {
238238
if (batchNode) {
239239
this.updateWithBatchNode(batchNode, rect, unused, capInsets);
240-
this.setAnchorPoint(cc.p(0.5, 0.5));
241240
}
242241
this.m_positionsAreDirty = true;
243242
return true;
@@ -377,16 +376,27 @@ cc.Scale9Sprite = cc.Node.extend({
377376
this._spriteRect = rect;
378377
this._originalSize = new cc.Size(rect.size.width, rect.size.height);
379378
this._preferredSize = this._originalSize;
380-
this._capInsetsInternal = capInsets;
379+
this._capInsetsInternal = capInsets || cc.RectZero();
381380

382381
// If there is no specified center region
383-
if (cc.Rect.CCRectEqualToRect(this._capInsetsInternal, cc.RectZero())) {
382+
if (cc.Rect.CCRectEqualToRect(this._capInsetsInternal, cc.RectZero()) ||
383+
cc.Rect.CCRectEqualToRect(this._capInsetsInternal, this._spriteRect)) {
384384
// Apply the 3x3 grid format
385385
this._capInsetsInternal = cc.RectMake(
386386
rect.origin.x + this._originalSize.width / 3,
387387
rect.origin.y + this._originalSize.height / 3,
388388
this._originalSize.width / 3,
389389
this._originalSize.height / 3);
390+
this._capInsets = null;
391+
}
392+
else
393+
{
394+
this._capInsetsInternal = cc.RectMake(
395+
rect.origin.x + this._capInsetsInternal.origin.x,
396+
rect.origin.y + this._capInsetsInternal.origin.y,
397+
this._capInsetsInternal.size.width,
398+
this._capInsetsInternal.size.height
399+
);
390400
}
391401

392402
// Get the image edges
@@ -456,6 +466,7 @@ cc.Scale9Sprite = cc.Node.extend({
456466

457467
this.setContentSize(rect.size);
458468
this.addChild(this._scale9Image);
469+
this.setAnchorPoint(cc.p(0.5, 0.5));
459470
return true;
460471
},
461472

0 commit comments

Comments
 (0)