From 912bd5651b59df4f38f2e31ddc70f95551b76969 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 16 Aug 2016 11:08:54 +0800 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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); } } }, From 4edadb381cd73857c8dc19b1fc7e653271e1e76a Mon Sep 17 00:00:00 2001 From: Nan Wang Date: Fri, 19 Aug 2016 15:55:56 +0800 Subject: [PATCH 06/10] update engine version --- CCBoot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CCBoot.js b/CCBoot.js index e5af2c5291..462bfea9f2 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -58,7 +58,7 @@ _p = null; * @name cc.ENGINE_VERSION */ var engineVersion; -engineVersion = '1.2.1-beta.4'; +engineVersion = '1.2.1-rc.1'; window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion; /** From 8e9016f3625e451b46fb4300e4997d85116bcb24 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 19 Aug 2016 16:06:55 +0800 Subject: [PATCH 07/10] Fix Orientation not supported in Fit height & Fit width mode --- cocos2d/core/platform/CCView.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/platform/CCView.js b/cocos2d/core/platform/CCView.js index c5703f7016..053632db0f 100644 --- a/cocos2d/core/platform/CCView.js +++ b/cocos2d/core/platform/CCView.js @@ -154,7 +154,7 @@ var View = cc._Class.extend({ * Constructor of View */ ctor: function () { - var _t = this, d = document, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy; + var _t = this, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy; __BrowserGetter.init(this); @@ -1055,7 +1055,15 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ */ var EqualToFrame = cc.ContainerStrategy.extend({ apply: function (view) { + var frameH = view._frameSize.height, containerStyle = cc.container.style; this._setupContainer(view, view._frameSize.width, view._frameSize.height); + // Setup container's margin and padding + if (view._isRotated) { + containerStyle.marginLeft = frameH + 'px'; + } + else { + containerStyle.margin = '0px'; + } } }); From 42b00ebcb9fc34414c40c81d893ac15088647a84 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 19 Aug 2016 16:25:06 +0800 Subject: [PATCH 08/10] Force update all scene after set design resolution policy --- cocos2d/core/platform/CCView.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cocos2d/core/platform/CCView.js b/cocos2d/core/platform/CCView.js index 053632db0f..d65dc9b54c 100644 --- a/cocos2d/core/platform/CCView.js +++ b/cocos2d/core/platform/CCView.js @@ -703,6 +703,9 @@ var View = cc._Class.extend({ // reset director's member variables to fit visible rect director.setGLDefaultValues(); } + else if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) { + cc.renderer._allNeedDraw = true; + } this._originalScaleX = this._scaleX; this._originalScaleY = this._scaleY; From 18632258a0c6e5a8f00238c66e83f959f12b684e Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Fri, 19 Aug 2016 16:55:08 +0800 Subject: [PATCH 09/10] fix possible memory leaks --- cocos2d/core/editbox/CCSGEditBox.js | 4 ++-- cocos2d/core/label/CCSGLabel.js | 19 +++++++++++++++++++ cocos2d/core/videoplayer/CCSGVideoPlayer.js | 4 ++-- cocos2d/core/webview/CCSGWebView.js | 4 ++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 4e6f82e24d..82647dd0c0 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -280,9 +280,9 @@ _ccsg.EditBox = _ccsg.Node.extend({ }, cleanup: function () { + this._super(); + this._renderCmd._removeDomInputControl(); - this.stopAllActions(); - this.unscheduleAllCallbacks(); }, _onTouchBegan: function (touch) { diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 9140092841..d7a2c868e8 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -380,6 +380,23 @@ _ccsg.Label = _ccsg.Node.extend({ this._notifyLabelSkinDirty(); }, + cleanup: function () { + this._super(); + + //remove the created DIV and style due to loading @font-face + if(this.__$fontStyle) { + if(document.body.contains(this.__$fontStyle)) { + document.body.removeChild(this.__$fontStyle); + } + } + + if(this.__$preloadDiv) { + if(document.body.contains(this.__$preloadDiv)) { + document.body.removeChild(this.__$preloadDiv); + } + } + }, + _loadTTFFont: function(fontHandle) { var ttfIndex = fontHandle.lastIndexOf(".ttf"); if (ttfIndex === -1) return fontHandle; @@ -401,6 +418,7 @@ _ccsg.Label = _ccsg.Node.extend({ fontStyle = document.createElement("style"); fontStyle.type = "text/css"; doc.body.appendChild(fontStyle); + this.__$fontStyle = fontStyle; var fontStr = ""; if (isNaN(fontFamilyName - 0)) @@ -421,6 +439,7 @@ _ccsg.Label = _ccsg.Node.extend({ _divStyle.left = "-100px"; _divStyle.top = "-100px"; doc.body.appendChild(preloadDiv); + this.__$preloadDiv = preloadDiv; self.scheduleOnce(function () { self._notifyLabelSkinDirty(); self.emit("load"); diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index 64dad7323e..831672ea52 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -139,9 +139,9 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ }, cleanup: function () { + this._super(); + this._renderCmd.removeDom(); - this.stopAllActions(); - this.unscheduleAllCallbacks(); }, onEnter: function () { diff --git a/cocos2d/core/webview/CCSGWebView.js b/cocos2d/core/webview/CCSGWebView.js index 7973a86a1f..db7f3295f3 100644 --- a/cocos2d/core/webview/CCSGWebView.js +++ b/cocos2d/core/webview/CCSGWebView.js @@ -185,9 +185,9 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{ * remove node */ cleanup: function(){ + this._super(); + this._renderCmd.removeDom(); - this.stopAllActions(); - this.unscheduleAllCallbacks(); }, setVisible: function ( visible ) { From b1078963506362a7e4d20b78a029fd8cbf5c316d Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Fri, 19 Aug 2016 17:09:51 +0800 Subject: [PATCH 10/10] rename member variables --- cocos2d/core/label/CCSGLabel.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index d7a2c868e8..8705cc99b0 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -384,15 +384,15 @@ _ccsg.Label = _ccsg.Node.extend({ this._super(); //remove the created DIV and style due to loading @font-face - if(this.__$fontStyle) { - if(document.body.contains(this.__$fontStyle)) { - document.body.removeChild(this.__$fontStyle); + if(this._fontFaceStyle) { + if(document.body.contains(this._fontFaceStyle)) { + document.body.removeChild(this._fontFaceStyle); } } - if(this.__$preloadDiv) { - if(document.body.contains(this.__$preloadDiv)) { - document.body.removeChild(this.__$preloadDiv); + if(this._preloadDiv) { + if(document.body.contains(this._preloadDiv)) { + document.body.removeChild(this._preloadDiv); } } }, @@ -418,7 +418,7 @@ _ccsg.Label = _ccsg.Node.extend({ fontStyle = document.createElement("style"); fontStyle.type = "text/css"; doc.body.appendChild(fontStyle); - this.__$fontStyle = fontStyle; + this._fontFaceStyle = fontStyle; var fontStr = ""; if (isNaN(fontFamilyName - 0)) @@ -439,7 +439,7 @@ _ccsg.Label = _ccsg.Node.extend({ _divStyle.left = "-100px"; _divStyle.top = "-100px"; doc.body.appendChild(preloadDiv); - this.__$preloadDiv = preloadDiv; + this._preloadDiv = preloadDiv; self.scheduleOnce(function () { self._notifyLabelSkinDirty(); self.emit("load");