From 912bd5651b59df4f38f2e31ddc70f95551b76969 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 16 Aug 2016 11:08:54 +0800 Subject: [PATCH 1/5] add min, max, step attribute --- cocos2d/core/platform/CCClass.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index cfc522cc92..ecf91a9247 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -1061,10 +1061,10 @@ function parseAttributes (attrs, className, propName) { } function parseSimpleAttr (attrName, expectType, attrCreater) { - var val = attrs[attrName]; - if (val) { + if (attrName in attrs) { + var val = attrs[attrName]; if (typeof val === expectType) { - if (typeof attrCreater === 'undefined') { + if ( !attrCreater ) { var attr = {}; attr[attrName] = val; result.push(attr); @@ -1074,7 +1074,7 @@ function parseAttributes (attrs, className, propName) { } } else if (CC_DEV) { - cc.error('The %s of %s.%s must be type %s', attrName, className, propName, expectType); + cc.error(ERR_Type, attrName, className, propName, expectType); } } } @@ -1128,13 +1128,16 @@ function parseAttributes (attrs, className, propName) { result.push({ min: range[0], max: range[1], step: range[2] }); } else if (CC_DEV) { - cc.error('The length of range array must be 2'); + cc.error('The length of range array must be equal or greater than 2'); } } else if (CC_DEV) { - cc.error(ERR_Type, '"range"', className + '.' + propName, 'array'); + cc.error(ERR_Type, 'range', className, propName, 'array'); } } + parseSimpleAttr('min', 'number'); + parseSimpleAttr('max', 'number'); + parseSimpleAttr('step', 'number'); return result; } From 2e319a3881bda1ae8cd48b74b2016090cb8922fc Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 16 Aug 2016 18:03:02 +0800 Subject: [PATCH 2/5] only register event when content is not null --- cocos2d/core/components/CCScrollView.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 762fc7f1db..9a209c87d2 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -1339,7 +1339,9 @@ var ScrollView = cc.Class({ this._calculateBoundary(); //Because widget component will adjust content position and scrollview position is correct after visit //So this event could make sure the content is on the correct position after loading. - cc.director.once(cc.Director.EVENT_AFTER_VISIT, this._adjustContentOutOfBoundary, this); + if(this.content) { + cc.director.once(cc.Director.EVENT_AFTER_VISIT, this._adjustContentOutOfBoundary, this); + } }, onDestroy: function() { From 722f1a0574137af90d32f052b73a94f06063e2ae Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 18 Aug 2016 16:06:32 +0800 Subject: [PATCH 3/5] Fix Label render command break BMFont batching --- cocos2d/core/label/CCSGLabel.js | 3 +++ cocos2d/core/label/CCSGLabelWebGLRenderCmd.js | 9 ++++++++- cocos2d/core/textures/CCTexture2D.js | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 34c6ca0545..9140092841 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -359,6 +359,7 @@ _ccsg.Label = _ccsg.Node.extend({ this._fontHandle = fontHandle; this._labelType = _ccsg.Label.Type.SystemFont; this._blendFunc = cc.BlendFunc._alphaPremultiplied(); + this._renderCmd._needDraw = true; this._notifyLabelSkinDirty(); this.emit('load'); return; @@ -367,11 +368,13 @@ _ccsg.Label = _ccsg.Node.extend({ if (extName === ".ttf") { this._labelType = _ccsg.Label.Type.TTF; this._blendFunc = cc.BlendFunc._alphaPremultiplied(); + this._renderCmd._needDraw = true; this._fontHandle = this._loadTTFFont(fontHandle); } else if (extName === ".fnt") { //todo add bmfont here this._labelType = _ccsg.Label.Type.BMFont; this._blendFunc = cc.BlendFunc._alphaNonPremultiplied(); + this._renderCmd._needDraw = false; this._initBMFontWithString(this._string, fontHandle, textureUrl); } this._notifyLabelSkinDirty(); diff --git a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js index 541e2f3c11..5247004163 100644 --- a/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js +++ b/cocos2d/core/label/CCSGLabelWebGLRenderCmd.js @@ -69,7 +69,8 @@ proto._updateDisplayOpacity = function (parentOpacity) { proto.transform = function (parentCmd, recursive) { this.originTransform(parentCmd, recursive); - var lx = 0, rx = this._labelCanvas.width, + var node = this._node, + lx = 0, rx = this._labelCanvas.width, by = 0, ty = this._labelCanvas.height, wt = this._worldTransform; @@ -83,6 +84,12 @@ proto.transform = function (parentCmd, recursive) { vert[3].x = rx * wt.a + by * wt.c + wt.tx; // br vert[3].y = rx * wt.b + by * wt.d + wt.ty; + if (!node._string || (node._labelType !== _ccsg.Label.Type.TTF && + node._labelType !== _ccsg.Label.Type.SystemFont)) { + // No culling for bmfont + return; + } + var rect = cc.visibleRect, vl = rect.left.x, vr = rect.right.x, vt = rect.top.y, vb = rect.bottom.y; if (((vert[0].x-vl) & (vert[1].x-vl) & (vert[2].x-vl) & (vert[3].x-vl)) >> 31 || // All outside left diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index 3f6a17b485..abafe8d952 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -96,7 +96,6 @@ var Texture2D = cc.Class(/** @lends cc.Texture2D# */{ this._isGray = false; } else if (cc._renderType === game.RENDER_TYPE_WEBGL) { - this._hasPremultipliedAlpha = false; this._pixelFormat = Texture2D.defaultPixelFormat; this._hasPremultipliedAlpha = false; this._hasMipmaps = false; From 7345fc9a788f6c07b4d9ce66981a34de2275f6d2 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 19 Aug 2016 10:02:55 +0800 Subject: [PATCH 4/5] Fix event listener mask can't be set if node is not in the hierarchy --- cocos2d/core/CCNode.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 3eb80ebbe3..828c33bdfe 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -969,6 +969,12 @@ var Node = cc.Class({ // activate cc.director.getActionManager().resumeTarget(this); cc.eventManager.resumeTarget(this); + if (this._touchListener) { + this._touchListener.mask = _searchMaskParent(this); + } + if (this._mouseListener) { + this._mouseListener.mask = _searchMaskParent(this); + } } else { // deactivate From a871df4fc8930ba582d11724c9a1cb576573cd9d Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Fri, 19 Aug 2016 11:54:11 +0800 Subject: [PATCH 5/5] fix outOfBoundary when scrollview size changed --- cocos2d/core/components/CCScrollView.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 9a209c87d2..33b34d1fc6 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -813,6 +813,7 @@ var ScrollView = cc.Class({ } this._moveContent(moveDelta); + this._adjustContentOutOfBoundary(); }, _calculateBoundary: function() { @@ -1331,6 +1332,7 @@ var ScrollView = cc.Class({ var newPosition = cc.pAdd(this.getContentPosition(), outOfBoundary); if(this.content) { this.content.setPosition(newPosition); + this._updateScrollBar(0); } } },