|
239 | 239 | cc.g_NumberOfDraws++;
|
240 | 240 | };
|
241 | 241 |
|
242 |
| - proto._changeTextureColor = function () { |
| 242 | + proto._updateColor = function () { |
243 | 243 | var node = this._node;
|
| 244 | + var displayedColor = this._displayedColor; |
| 245 | + |
| 246 | + if(this._colorized){ |
| 247 | + if(displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255){ |
| 248 | + this._colorized = false; |
| 249 | + node.texture = this._originalTexture; |
| 250 | + return; |
| 251 | + } |
| 252 | + }else |
| 253 | + if(displayedColor.r === 255 && displayedColor.g === 255 && displayedColor.b === 255) |
| 254 | + return; |
| 255 | + |
244 | 256 | var locElement, locTexture = node._texture, locRect = this._textureCoord;
|
245 | 257 | if (locTexture && locRect.validRect && this._originalTexture) {
|
246 | 258 | locElement = locTexture.getHtmlElementObj();
|
|
253 | 265 | this._colorized = true;
|
254 | 266 | //generate color texture cache
|
255 | 267 | if (locElement instanceof HTMLCanvasElement && !this._rectRotated && !this._newTextureWhenChangeColor)
|
256 |
| - cc.Sprite.CanvasRenderCmd._generateTintImage(locElement, cacheTextureForColor, this._displayedColor, locRect, locElement); |
| 268 | + cc.Sprite.CanvasRenderCmd._generateTintImage(locElement, cacheTextureForColor, displayedColor, locRect, locElement); |
257 | 269 | else {
|
258 |
| - locElement = cc.Sprite.CanvasRenderCmd._generateTintImage(locElement, cacheTextureForColor, this._displayedColor, locRect); |
| 270 | + locElement = cc.Sprite.CanvasRenderCmd._generateTintImage(locElement, cacheTextureForColor, displayedColor, locRect); |
259 | 271 | locTexture = new cc.Texture2D();
|
260 | 272 | locTexture.initWithElement(locElement);
|
261 | 273 | locTexture.handleLoadedTexture();
|
|
266 | 278 | this._colorized = true;
|
267 | 279 | if (locElement instanceof HTMLCanvasElement && !this._rectRotated && !this._newTextureWhenChangeColor
|
268 | 280 | && this._originalTexture._htmlElementObj != locElement)
|
269 |
| - cc.Sprite.CanvasRenderCmd._generateTintImageWithMultiply(this._originalTexture._htmlElementObj, this._displayedColor, locRect, locElement); |
| 281 | + cc.Sprite.CanvasRenderCmd._generateTintImageWithMultiply(this._originalTexture._htmlElementObj, displayedColor, locRect, locElement); |
270 | 282 | else {
|
271 |
| - locElement = cc.Sprite.CanvasRenderCmd._generateTintImageWithMultiply(this._originalTexture._htmlElementObj, this._displayedColor, locRect); |
| 283 | + locElement = cc.Sprite.CanvasRenderCmd._generateTintImageWithMultiply(this._originalTexture._htmlElementObj, displayedColor, locRect); |
272 | 284 | locTexture = new cc.Texture2D();
|
273 | 285 | locTexture.initWithElement(locElement);
|
274 | 286 | locTexture.handleLoadedTexture();
|
|
293 | 305 | if (textureLoaded) {
|
294 | 306 | var curColor = node.getColor();
|
295 | 307 | if (curColor.r !== 255 || curColor.g !== 255 || curColor.b !== 255)
|
296 |
| - this._changeTextureColor(); |
| 308 | + this._updateColor(); |
297 | 309 | }
|
298 | 310 | };
|
299 | 311 |
|
|
327 | 339 |
|
328 | 340 | proto._updateDisplayColor = function (parentColor) {
|
329 | 341 | cc.Node.CanvasRenderCmd.prototype._updateDisplayColor.call(this, parentColor);
|
330 |
| - this._changeTextureColor(); |
331 |
| - }; |
332 |
| - |
333 |
| - proto._syncDisplayColor = function(parentColor){ |
334 |
| - cc.Node.CanvasRenderCmd.prototype._syncDisplayColor.call(this, parentColor); |
335 |
| - this._changeTextureColor(); |
| 342 | + this._updateColor(); |
336 | 343 | };
|
337 | 344 |
|
338 | 345 | proto._spriteFrameLoadedCallback = function (spriteFrame) {
|
|
342 | 349 | //TODO change
|
343 | 350 | var curColor = _t.getColor();
|
344 | 351 | if (curColor.r !== 255 || curColor.g !== 255 || curColor.b !== 255)
|
345 |
| - _t._changeTextureColor(); |
| 352 | + _t._updateColor(); |
346 | 353 |
|
347 | 354 | _t.dispatchEvent("load");
|
348 | 355 | };
|
|
368 | 375 | //set the texture's color after the it loaded
|
369 | 376 | var locColor = locRenderCmd._displayedColor;
|
370 | 377 | if (locColor.r != 255 || locColor.g != 255 || locColor.b != 255)
|
371 |
| - locRenderCmd._changeTextureColor(); |
| 378 | + locRenderCmd._updateColor(); |
372 | 379 |
|
373 | 380 | // by default use "Self Render".
|
374 | 381 | // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
|
|
0 commit comments