diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 75983692bd..dbf69a2bc8 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -64,7 +64,7 @@ cc.g_NumberOfDraws = 0; * - Scheduled timers & drawing are synchronizes with the refresh rate of the display
* - Only supports animation intervals of 1/60 1/30 & 1/15
*

- * @class Director + * @class director */ cc.Director = Class.extend(/** @lends cc.Director# */{ //Variables diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 94d3c1ce51..385b9f84bb 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -375,6 +375,10 @@ var Sprite = cc.Class({ _initSgNode: function () { var sgNode = this._sgNode; + if ( !this.enabledInHierarchy ) { + sgNode.setVisible(false); + } + this._applySpriteFrame(null); // should keep the size of the sg node the same as entity, diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js index 1dd7af64e3..857ba6d3e5 100644 --- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js @@ -29,12 +29,12 @@ http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java) http://www.angelcode.com/products/bmfont/ (Free, Windows only) ****************************************************************************/ -(function() { - _ccsg.Label.TTFLabelBaker = function() { +(function () { + _ccsg.Label.TTFLabelBaker = function () { }; var proto = _ccsg.Label.TTFLabelBaker.prototype = Object.create(Object.prototype); - proto._getLineHeight = function() { + proto._getLineHeight = function () { //todo refine it var nodeSpacingY = this._node.getLineHeight(); if (nodeSpacingY === 0) { @@ -45,7 +45,7 @@ return nodeSpacingY | 0; }; - proto._prepareQuad = function() { + proto._prepareQuad = function () { var quad = this._quad; var white = cc.color(255, 255, 255, this._displayedOpacity); var width = this._node._contentSize.width; @@ -89,7 +89,7 @@ } var text = strArr; var allWidth = ctx.measureText(text).width; - while(allWidth > maxWidth && text.length > 1){ + while (allWidth > maxWidth && text.length > 1) { var fuzzyLen = text.length * ( maxWidth / allWidth ) | 0; var tmpText = text.substr(fuzzyLen); @@ -156,14 +156,14 @@ text = sLine || tmpText; allWidth = ctx.measureText(text).width; } - if(text.length > 0) { + if (text.length > 0) { wrappedWords.push(text); } - + return wrappedWords; }; - - proto._updateDisplayOpacity = function(parentOpacity) { + + proto._updateDisplayOpacity = function (parentOpacity) { _ccsg.Node.RenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity); //specify opacity to quad var color = cc.color(255, 255, 255, this._displayedOpacity); @@ -174,14 +174,14 @@ quad._tr.colors = color; this._quadDirty = true; }; - + proto._updateDisplayColor = function (parentColor) { _ccsg.Node.RenderCmd.prototype._updateDisplayColor.call(this, parentColor); var node = this._node; node._labelSkinDirty = true; }; - - proto._bakeLabel = function() { + + proto._bakeLabel = function () { var node = this._node; this._drawFontsize = node._fontSize; var ctx = this._labelContext; @@ -225,7 +225,7 @@ canvasSizeY = this._splitedStrings.length * this._getLineHeight(); node._setDimensions(cc.size(canvasSizeX, canvasSizeY)); } - } else if(_ccsg.Label.Overflow.SHRINK === node._overFlow) { + } else if (_ccsg.Label.Overflow.SHRINK === node._overFlow) { this._splitedStrings = paragraphedStrings; //shrink if (node._isWrapText) { @@ -330,14 +330,14 @@ this._labelTexture.handleLoadedTexture(); }; - proto._rebuildLabelSkin = function() { + proto._rebuildLabelSkin = function () { var node = this._node; if (node._labelSkinDirty) { - if(node._labelType === _ccsg.Label.Type.TTF || - node._labelType === _ccsg.Label.Type.SystemFont){ + if (node._labelType === _ccsg.Label.Type.TTF || + node._labelType === _ccsg.Label.Type.SystemFont) { this._bakeLabel(); this._prepareQuad(); - }else { + } else { node._updateContent(); } this._node._labelSkinDirty = false; @@ -345,8 +345,8 @@ }; })(); -(function() { - _ccsg.Label.CanvasRenderCmd = function(renderableObject) { +(function () { + _ccsg.Label.CanvasRenderCmd = function (renderableObject) { _ccsg.Node.CanvasRenderCmd.call(this, renderableObject); this._needDraw = true; this._labelTexture = new cc.Texture2D(); @@ -366,13 +366,13 @@ proto.constructor = _ccsg.Label.CanvasRenderCmd; - proto.rendering = function(ctx, scaleX, scaleY) { + proto.rendering = function (ctx, scaleX, scaleY) { this._rebuildLabelSkin(); var node = this._node; if (node._labelType === _ccsg.Label.Type.TTF || - node._labelType === _ccsg.Label.Type.SystemFont) { + node._labelType === _ccsg.Label.Type.SystemFont) { var locDisplayOpacity = this._displayedOpacity; var alpha = locDisplayOpacity / 255; //var locTexture = this._labelTexture; @@ -386,41 +386,39 @@ wrapper.setGlobalAlpha(alpha); if (this._labelTexture) { + var sx, sy, sw, sh; + var x, y, w, h; - var quad = this._quad; { - var sx, sy, sw, sh; - var x, y, w, h; + x = 0; + y = -this._node._contentSize.height; + w = this._node._contentSize.width; + h = this._node._contentSize.height; - x = quad._bl.vertices.x; - y = quad._bl.vertices.y; - w = quad._tr.vertices.x - quad._bl.vertices.x; - h = quad._tr.vertices.y - quad._bl.vertices.y; - y = -y - h; - var textureWidth = this._labelTexture.getPixelWidth(); - var textureHeight = this._labelTexture.getPixelHeight(); + var textureWidth = this._labelTexture.getPixelWidth(); + var textureHeight = this._labelTexture.getPixelHeight(); - sx = quad._bl.texCoords.u * textureWidth; - sy = quad._bl.texCoords.v * textureHeight; - sw = (quad._tr.texCoords.u - quad._bl.texCoords.u) * textureWidth; - sh = (quad._tr.texCoords.v - quad._bl.texCoords.v) * textureHeight; + sx = 0; + sy = 0; + sw = textureWidth; + sh = textureHeight; - x = x * scaleX; - y = y * scaleY; - w = w * scaleX; - h = h * scaleY; + x = x * scaleX; + y = y * scaleY; + w = w * scaleX; + h = h * scaleY; - var image = this._labelTexture._htmlElementObj; - if (this._labelTexture._pattern !== "") { - wrapper.setFillStyle(context.createPattern(image, this._labelTexture._pattern)); - context.fillRect(x, y, w, h); - } else { + var image = this._labelTexture._htmlElementObj; + if (this._labelTexture._pattern !== "") { + wrapper.setFillStyle(context.createPattern(image, this._labelTexture._pattern)); + context.fillRect(x, y, w, h); + } else { + if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) { context.drawImage(image, - sx, sy, sw, sh, - x, y, w, h); + sx, sy, sw, sh, + x, y, w, h); } } - } cc.g_NumberOfDraws = cc.g_NumberOfDraws + 1; } diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js index aa7352d783..d633b53603 100644 --- a/cocos2d/core/platform/CCEGLView.js +++ b/cocos2d/core/platform/CCEGLView.js @@ -114,7 +114,7 @@ switch(cc.__BrowserGetter.adaptationType){ * the standard way to use it is by calling:
* - cc.view.methodName();
* - * @class EGLView + * @class view * @extends _Class */ cc.EGLView = cc._Class.extend(/** @lends cc.view# */{ diff --git a/cocos2d/core/platform/callbacks-invoker.js b/cocos2d/core/platform/callbacks-invoker.js index 17e62e82ee..ae304688cc 100644 --- a/cocos2d/core/platform/callbacks-invoker.js +++ b/cocos2d/core/platform/callbacks-invoker.js @@ -76,7 +76,7 @@ CallbacksHandler.prototype.has = function (key, callback, target) { if (callbackTarget === target) { return true; } - index = list.indexOf(callback, index + 1); + index = cc.js.array.indexOf.call(list, callback, index + 1); } // callback given but not found return false; @@ -131,7 +131,7 @@ CallbacksHandler.prototype.remove = function (key, callback, target) { break; } - index = list.indexOf(callback, index + 1); + index = cc.js.array.indexOf.call(list, callback, index + 1); } return true; } diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js index 1bb5289d85..b91df6bbfb 100644 --- a/cocos2d/core/platform/js.js +++ b/cocos2d/core/platform/js.js @@ -628,7 +628,25 @@ js.array = { for (i = 0; i < len; i += 1) arr_clone[i] = array[i]; return arr_clone; - } + }, + + /** + * Exact same function as Array.prototype.indexOf. + * HACK: ugliy hack for Baidu mobile browser compatibility, + * stupid Baidu guys modify Array.prototype.indexOf for all pages loaded, + * their version changes strict comparison to non-strict comparison, + * it also ignores the second parameter of the original API, + * and this will cause event handler enter infinite loop. + * Baidu developers, if you ever see this documentation, + * here is the standard: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf + * Seriously ! + * + * @method indexOf + * @param {any} searchElement Element to locate in the array. + * @param {Number} [fromIndex=0] The index to start the search at + * @return {Number} returns the first index at which a given element can be found in the array, or -1 if it is not present. + */ + indexOf: Array.prototype.indexOf, }; cc.js = js; diff --git a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js index 65b0281fe7..36844c4d72 100644 --- a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js +++ b/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js @@ -71,7 +71,7 @@ var wrapper = ctx || cc._renderContext, context = wrapper.getContext(); wrapper.setTransform(this._worldTransform, scaleX, scaleY); - wrapper.setCompositeOperation(node._blendFunc); + wrapper.setCompositeOperation(_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(node._blendFunc)); wrapper.setGlobalAlpha(alpha); if(this._textureToRender) { @@ -94,10 +94,10 @@ var textureWidth = this._textureToRender.getPixelWidth(); var textureHeight = this._textureToRender.getPixelHeight(); - sx = quads[i]._bl.texCoords.u * textureWidth; - sy = quads[i]._bl.texCoords.v * textureHeight; + sx = quads[i]._tl.texCoords.u * textureWidth; + sy = quads[i]._tl.texCoords.v * textureHeight; sw = (quads[i]._tr.texCoords.u - quads[i]._bl.texCoords.u) * textureWidth; - sh = (quads[i]._tr.texCoords.v - quads[i]._bl.texCoords.v) * textureHeight; + sh = (quads[i]._bl.texCoords.v - quads[i]._tr.texCoords.v) * textureHeight; x = x * scaleX; y = y * scaleY; @@ -109,9 +109,11 @@ wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern)); context.fillRect(x, y, w, h); } else { - context.drawImage(image, - sx, sy, sw, sh, - x, y, w, h); + if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) { + context.drawImage(image, + sx, sy, sw, sh, + x, y, w, h); + } } }