From d29d80d435454e4e8e614adf91556614426de8db Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Tue, 15 Nov 2016 18:17:35 +0800 Subject: [PATCH 01/18] Can't stop audio --- cocos2d/audio/CCAudio.js | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index aaf45a66b9..7ec520afb9 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -144,7 +144,6 @@ Audio.State = { this._state = Audio.State.PLAYING; if (this._audioType === Audio.Type.DOM && this._element.paused) { - this.stop(); touchPlayList.push({ instance: this, offset: 0, audio: this._element }); } From 87fb1fe4ead0e10d9b1b54916b2c464c6f663cce Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 17 Nov 2016 14:36:55 +0800 Subject: [PATCH 02/18] add UnifiedSize for PageView fireball/issues/4714 --- cocos2d/core/components/CCPageView.js | 192 +++++++++++++++++++++----- 1 file changed, 159 insertions(+), 33 deletions(-) diff --git a/cocos2d/core/components/CCPageView.js b/cocos2d/core/components/CCPageView.js index a70bd5af27..05a29a7a22 100644 --- a/cocos2d/core/components/CCPageView.js +++ b/cocos2d/core/components/CCPageView.js @@ -23,8 +23,25 @@ THE SOFTWARE. ****************************************************************************/ -// 快速滑动的临界值 -var _CUSTOMSCROLLTHRESHOLD = 200; +/** + * !#en The Page View unified Size + * !#zh 页面视图每个页面统一的大小类型 + * @enum PageView.UnifiedSize + */ +var UnifiedSize = cc.Enum({ + /** + * !#en Each page is uniform in size + * !#zh 每个页面统一大小 + * @property {Number} Unified + */ + Unified: 0, + /** + * !#en Each page size is free + * !#zh 每个页面大小随意 + * @property {Number} Free + */ + Free: 1 +}); /** * !#en The Page View Direction @@ -82,9 +99,26 @@ var PageView = cc.Class({ this._curPageIdx = 0; this._lastPageIdx = 0; this._pages = []; + this._scrollCenterOffsetX = []; // 每一个页面居中时需要的偏移量(X) + this._scrollCenterOffsetY = []; // 每一个页面居中时需要的偏移量(Y) }, properties: { + + /** + * !#en Each page size mode in the page view + * !#zh 页面视图中每个页面大小类型 + * @property {PageView.UnifiedSize} unifiedSize + */ + unifiedSize: { + default: UnifiedSize.Unified, + type: UnifiedSize, + tooltip: 'i18n:COMPONENT.pageview.unifiedsize', + notify: function() { + this._syncUnifiedSize(); + } + }, + /** * !#en The page view direction * !#zh 页面视图滚动类型 @@ -114,6 +148,23 @@ var PageView = cc.Class({ tooltip: 'i18n:COMPONENT.pageview.scrollThreshold' }, + /** + * !#en + * Auto page turning velocity threshold. When users swipe the PageView quickly, + * it will calculate a velocity based on the scroll distance and time, + * if the calculated velocity is larger than the threshold, then it will trigger page turning. + * !#zh + * 快速滑动翻页临界值。 + * 当用户快速滑动时,会根据滑动开始和结束的距离与时间计算出一个速度值, + * 该值与此临界值相比较,如果大于临界值,则进行自动翻页。 + * @property {Number} pageTurningVelocity + */ + pageTurningVelocity: { + default: 100, + type: cc.Float, + tooltip: 'i18n:COMPONENT.pageview.pageTurningVelocity' + }, + /** * !#en Change the PageTurning event timing of PageView. * !#zh 设置 PageView PageTurning 事件的发送时机。 @@ -155,19 +206,16 @@ var PageView = cc.Class({ }, statics: { + UnifiedSize: UnifiedSize, Direction: Direction, EventType: EventType }, __preload: function () { this._super(); - this.node.on('size-changed', this._updateAllPagesSize, this); - this._syncScrollDirection(); - }, - - _syncScrollDirection: function () { - this.horizontal = this.direction === Direction.Horizontal; - this.vertical = this.direction === Direction.Vertical; + if (this.unifiedSize === UnifiedSize.Unified) { + this.node.on('size-changed', this._updateAllPagesSize, this); + } }, onEnable: function () { @@ -193,7 +241,9 @@ var PageView = cc.Class({ onDestroy: function() { this._super(); - this.node.off('size-changed', this._updateAllPagesSize, this); + if (this.unifiedSize === UnifiedSize.Unified) { + this.node.off('size-changed', this._updateAllPagesSize, this); + } }, /** @@ -329,6 +379,35 @@ var PageView = cc.Class({ return this.pageTurningEventTiming; }, + _syncScrollDirection: function () { + this.horizontal = this.direction === Direction.Horizontal; + this.vertical = this.direction === Direction.Vertical; + }, + + _syncUnifiedSize: function () { + if (!this.content) { return; } + var layout = this.content.getComponent(cc.Layout); + if (layout) { + if (this._pages.length === 0) { + layout.padding = 0; + } + else { + var lastPage = this._pages[this._pages.length - 1]; + if (this.unifiedSize === UnifiedSize.Free) { + if (this.direction === Direction.Horizontal) { + layout.paddingLeft = (this.node.width - this._pages[0].width) / 2; + layout.paddingRight = (this.node.width - lastPage.width) / 2; + } + else if (this.direction === Direction.Vertical) { + layout.paddingTop = (this.node.height - this._pages[0].height) / 2; + layout.paddingBottom = (this.node.height - lastPage.height) / 2; + } + } + } + layout._updateLayout(); + } + }, + // 刷新页面视图 _updatePageView: function () { var pageCount = this._pages.length; @@ -345,6 +424,12 @@ var PageView = cc.Class({ // 进行排序 for (var i = 0; i < pageCount; ++i) { this._pages[i].setSiblingIndex(i); + if (this.direction === Direction.Horizontal) { + this._scrollCenterOffsetX[i] = Math.abs(this.content.x + this._pages[i].x); + } + else { + this._scrollCenterOffsetY[i] = Math.abs(this.content.y + this._pages[i].y); + } } // 刷新 indicator 信息与状态 if (this.indicator) { @@ -370,6 +455,9 @@ var PageView = cc.Class({ if (this._pages.indexOf(page) >= 0) { continue; } this._pages.push(page); } + this._syncScrollDirection(); + this._syncUnifiedSize(); + this._updatePageView(); }, _dispatchPageTurningEvent: function () { @@ -380,23 +468,63 @@ var PageView = cc.Class({ }, // 是否超过自动滚动临界值 - _isScrollable: function (offset) { + _isScrollable: function (offset, index, nextIndex) { + if (this.unifiedSize === UnifiedSize.Free) { + var curPageCenter, nextPageCenter; + if (this.direction === Direction.Horizontal) { + curPageCenter = this._scrollCenterOffsetX[index]; + nextPageCenter = this._scrollCenterOffsetX[nextIndex]; + return Math.abs(offset.x) >= Math.abs(curPageCenter - nextPageCenter) * this.scrollThreshold; + } + else if (this.direction === Direction.Vertical) { + curPageCenter = this._scrollCenterOffsetY[index]; + nextPageCenter = this._scrollCenterOffsetY[nextIndex]; + return Math.abs(offset.y) >= Math.abs(curPageCenter - nextPageCenter) * this.scrollThreshold; + } + } + else { + if (this.direction === Direction.Horizontal) { + return Math.abs(offset.x) >= this.node.width * this.scrollThreshold; + } + else if (this.direction === Direction.Vertical) { + return Math.abs(offset.y) >= this.node.height * this.scrollThreshold; + } + } + }, + + // 快速滑动 + _isQuicklyScrollable: function (touchMoveVelocity) { if (this.direction === Direction.Horizontal) { - return Math.abs(offset.x) >= this.node.width * this.scrollThreshold; + if (Math.abs(touchMoveVelocity.x) > this.pageTurningVelocity) { + return true; + } } else if (this.direction === Direction.Vertical) { - return Math.abs(offset.y) >= this.node.height * this.scrollThreshold; + if (Math.abs(touchMoveVelocity.y) > this.pageTurningVelocity) { + return true; + } } + return false; }, // 通过 idx 获取偏移值数值 _moveOffsetValue: function (idx) { var offset = cc.p(0, 0); - if (this.direction === Direction.Horizontal) { - offset.x = idx * this.node.width; + if (this.unifiedSize === UnifiedSize.Free) { + if (this.direction === Direction.Horizontal) { + offset.x = this._scrollCenterOffsetX[idx]; + } + else if (this.direction === Direction.Vertical) { + offset.y = this._scrollCenterOffsetY[idx]; + } } - else if (this.direction === Direction.Vertical) { - offset.y = idx * this.node.height; + else { + if (this.direction === Direction.Horizontal) { + offset.x = idx * this.node.width; + } + else if (this.direction === Direction.Vertical) { + offset.y = idx * this.node.height; + } } return offset; }, @@ -416,43 +544,41 @@ var PageView = cc.Class({ _handleReleaseLogic: function(touch) { var bounceBackStarted = this._startBounceBackIfNeeded(); if (!bounceBackStarted) { - var idx = this._curPageIdx; - if (idx === 0 && this._pages.length === 1) { - return; - } + var index = this._curPageIdx; var moveOffset = cc.pSub(this._touchBeganPosition, this._touchEndPosition); - if (this._isScrollable(moveOffset)) { - idx = this._updatePageIndex(moveOffset); - } - else { - var touchMoveVelocity = this._calculateTouchMoveVelocity(); - if (Math.abs(touchMoveVelocity.x) > _CUSTOMSCROLLTHRESHOLD) { - idx = this._updatePageIndex(moveOffset); + var nextIndex = this._updatePageIndex(moveOffset); + if (nextIndex < this._pages.length) { + if (this._isScrollable(moveOffset, index, nextIndex)) { + this.scrollToPage(nextIndex); + return; + } + else { + var touchMoveVelocity = this._calculateTouchMoveVelocity(); + if (this._isQuicklyScrollable(touchMoveVelocity)) { + this.scrollToPage(nextIndex); + return; + } } } - this.scrollToPage(idx); + this.scrollToPage(index); } }, _onTouchBegan: function (event, captureListeners) { - this._touchBeganPosition = event.touch.getLocation(); this._super(event, captureListeners); }, _onTouchMoved: function (event, captureListeners) { - this._super(event, captureListeners); }, _onTouchEnded: function (event, captureListeners) { - this._touchEndPosition = event.touch.getLocation(); this._super(event, captureListeners); }, _onTouchCancelled: function (event, captureListeners) { - this._touchEndPosition = event.touch.getLocation(); this._super(event, captureListeners); }, From 99d386bfef3e532f3c55cf5fcfafb71eb9a092ba Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Thu, 17 Nov 2016 17:46:40 +0800 Subject: [PATCH 03/18] fix migrate padding data --- cocos2d/core/components/CCLayout.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 0e3f7780a5..fbed1ceaf0 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -272,8 +272,7 @@ var Layout = cc.Class({ }, _N$padding: { - default: 0, - editorOnly: true + default: 0 }, /** * !#en The left padding of layout, it only effect the layout in one direction. @@ -415,10 +414,8 @@ var Layout = cc.Class({ this.node.setContentSize(this._layoutSize); } - if(CC_EDITOR) { - if(this._N$padding !== 0) { - this._migratePaddingData(); - } + if(this._N$padding !== 0) { + this._migratePaddingData(); } this.node.on('size-changed', this._resized, this); From ce9c752f0cafb52ddecd07debc93f1bd495ffd8a Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Thu, 17 Nov 2016 18:09:00 +0800 Subject: [PATCH 04/18] optimize custom ttf font load notification --- cocos2d/core/label/CCTextUtils.js | 57 +++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/label/CCTextUtils.js b/cocos2d/core/label/CCTextUtils.js index bae23412df..cb655bbe52 100644 --- a/cocos2d/core/label/CCTextUtils.js +++ b/cocos2d/core/label/CCTextUtils.js @@ -27,6 +27,7 @@ var CustomFontDescriptor = function() { this._status = 'unloaded'; //when font is loaded, it will notify each observer in the observers array this._observers = []; + this._isLoadWithCSS = false; }; CustomFontDescriptor.prototype.onLoaded = function () { @@ -48,6 +49,10 @@ CustomFontDescriptor.prototype.addHandler = function (callback) { var CustomFontLoader = { _fontCache: {}, + _fontWidthCache: {}, + _canvasContext: null, + _testString: "BESbswy", + _allFontsLoaded: false, loadTTF: function (url, callback) { //these platforms support window.FontFace, but it sucks sometimes. var useFontFace = (cc.sys.browserType !== cc.sys.BROWSER_TYPE_BAIDU @@ -59,6 +64,33 @@ var CustomFontLoader = { } else { this._loadWithCSS(url, callback); } + + if(!cc.director.getScheduler().isScheduled(this._checkFontLoaded, this)) { + cc.director.getScheduler().schedule(this._checkFontLoaded, this, 0.1); + } + }, + + _checkFontLoaded: function () { + this._allFontsLoaded = true; + + for(var k in this._fontCache) { + var fontDescriptor = this._fontCache[k]; + if(fontDescriptor.isLoaded() || !fontDescriptor._isLoadWithCSS) { + continue; + } + var oldWidth = this._fontWidthCache[k]; + this._canvasContext.font = '40px ' + k; + var newWidth = this._canvasContext.measureText(this._testString).width; + if(oldWidth !== newWidth) { + fontDescriptor.onLoaded(); + } else { + this._allFontsLoaded = false; + } + } + + if(this._allFontsLoaded) { + cc.director.getScheduler().unschedule(this._checkFontLoaded, this); + } }, _loadWithFontFace: function(url, callback) { @@ -116,12 +148,33 @@ var CustomFontLoader = { fontDescriptor = new CustomFontDescriptor(); fontDescriptor.addHandler(callback); this._fontCache[fontFamilyName] = fontDescriptor; + fontDescriptor._isLoadWithCSS = true; + if(!this._canvasContext) { + var labelCanvas = document.createElement('canvas'); + labelCanvas.width = 100; + labelCanvas.height = 100; + this._canvasContext = labelCanvas.getContext('2d'); + } + + var fontDesc = '40px ' + fontFamilyName; + this._canvasContext.font = fontDesc; + + var width = this._canvasContext.measureText(this._testString).width; + this._fontWidthCache[fontFamilyName] = width; + + var self = this; fontStyle.onload = function() { setTimeout(function () { - fontDescriptor.onLoaded(); - }, 100); + //in case some font won't cause the width as to system font. + if(!self._allFontsLoaded) { + cc.log("force notify all fonts loaded!"); + fontDescriptor.onLoaded(); + cc.director.getScheduler().unschedule(this._checkFontLoaded, this); + } + }, 20000); }; + } else { if(!fontDescriptor.isLoaded()) { fontDescriptor.addHandler(callback); From 58449afe3206bfd384b53521a46631e19165f8ca Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 18 Nov 2016 17:34:13 +0800 Subject: [PATCH 05/18] update CCPageView --- cocos2d/core/components/CCPageView.js | 50 +++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/cocos2d/core/components/CCPageView.js b/cocos2d/core/components/CCPageView.js index 05a29a7a22..11cf94fa07 100644 --- a/cocos2d/core/components/CCPageView.js +++ b/cocos2d/core/components/CCPageView.js @@ -24,19 +24,19 @@ ****************************************************************************/ /** - * !#en The Page View unified Size + * !#en The Page View Size Mode * !#zh 页面视图每个页面统一的大小类型 - * @enum PageView.UnifiedSize + * @enum PageView.SizeMode */ -var UnifiedSize = cc.Enum({ +var SizeMode = cc.Enum({ /** - * !#en Each page is uniform in size + * !#en Each page is unified in size * !#zh 每个页面统一大小 * @property {Number} Unified */ Unified: 0, /** - * !#en Each page size is free + * !#en Each page is in free size * !#zh 每个页面大小随意 * @property {Number} Free */ @@ -106,16 +106,16 @@ var PageView = cc.Class({ properties: { /** - * !#en Each page size mode in the page view + * !#en Specify the size type of each page in PageView. * !#zh 页面视图中每个页面大小类型 - * @property {PageView.UnifiedSize} unifiedSize + * @property {PageView.SizeMode} sizeMode */ - unifiedSize: { - default: UnifiedSize.Unified, - type: UnifiedSize, - tooltip: 'i18n:COMPONENT.pageview.unifiedsize', + sizeMode: { + default: SizeMode.Unified, + type: SizeMode, + tooltip: 'i18n:COMPONENT.pageview.sizeMode', notify: function() { - this._syncUnifiedSize(); + this._syncSizeMode(); } }, @@ -157,12 +157,12 @@ var PageView = cc.Class({ * 快速滑动翻页临界值。 * 当用户快速滑动时,会根据滑动开始和结束的距离与时间计算出一个速度值, * 该值与此临界值相比较,如果大于临界值,则进行自动翻页。 - * @property {Number} pageTurningVelocity + * @property {Number} autoPageTurningThreshold */ - pageTurningVelocity: { + autoPageTurningThreshold: { default: 100, type: cc.Float, - tooltip: 'i18n:COMPONENT.pageview.pageTurningVelocity' + tooltip: 'i18n:COMPONENT.pageview.autoPageTurningThreshold' }, /** @@ -206,14 +206,14 @@ var PageView = cc.Class({ }, statics: { - UnifiedSize: UnifiedSize, + SizeMode: SizeMode, Direction: Direction, EventType: EventType }, __preload: function () { this._super(); - if (this.unifiedSize === UnifiedSize.Unified) { + if (this.sizeMode === SizeMode.Unified) { this.node.on('size-changed', this._updateAllPagesSize, this); } }, @@ -241,7 +241,7 @@ var PageView = cc.Class({ onDestroy: function() { this._super(); - if (this.unifiedSize === UnifiedSize.Unified) { + if (this.sizeMode === SizeMode.Unified) { this.node.off('size-changed', this._updateAllPagesSize, this); } }, @@ -384,7 +384,7 @@ var PageView = cc.Class({ this.vertical = this.direction === Direction.Vertical; }, - _syncUnifiedSize: function () { + _syncSizeMode: function () { if (!this.content) { return; } var layout = this.content.getComponent(cc.Layout); if (layout) { @@ -393,7 +393,7 @@ var PageView = cc.Class({ } else { var lastPage = this._pages[this._pages.length - 1]; - if (this.unifiedSize === UnifiedSize.Free) { + if (this.sizeMode === SizeMode.Free) { if (this.direction === Direction.Horizontal) { layout.paddingLeft = (this.node.width - this._pages[0].width) / 2; layout.paddingRight = (this.node.width - lastPage.width) / 2; @@ -456,7 +456,7 @@ var PageView = cc.Class({ this._pages.push(page); } this._syncScrollDirection(); - this._syncUnifiedSize(); + this._syncSizeMode(); this._updatePageView(); }, @@ -469,7 +469,7 @@ var PageView = cc.Class({ // 是否超过自动滚动临界值 _isScrollable: function (offset, index, nextIndex) { - if (this.unifiedSize === UnifiedSize.Free) { + if (this.sizeMode === SizeMode.Free) { var curPageCenter, nextPageCenter; if (this.direction === Direction.Horizontal) { curPageCenter = this._scrollCenterOffsetX[index]; @@ -495,12 +495,12 @@ var PageView = cc.Class({ // 快速滑动 _isQuicklyScrollable: function (touchMoveVelocity) { if (this.direction === Direction.Horizontal) { - if (Math.abs(touchMoveVelocity.x) > this.pageTurningVelocity) { + if (Math.abs(touchMoveVelocity.x) > this.autoPageTurningThreshold) { return true; } } else if (this.direction === Direction.Vertical) { - if (Math.abs(touchMoveVelocity.y) > this.pageTurningVelocity) { + if (Math.abs(touchMoveVelocity.y) > this.autoPageTurningThreshold) { return true; } } @@ -510,7 +510,7 @@ var PageView = cc.Class({ // 通过 idx 获取偏移值数值 _moveOffsetValue: function (idx) { var offset = cc.p(0, 0); - if (this.unifiedSize === UnifiedSize.Free) { + if (this.sizeMode === SizeMode.Free) { if (this.direction === Direction.Horizontal) { offset.x = this._scrollCenterOffsetX[idx]; } From 6faadf74455fb3f90434532b6eb2d53d16cff7d6 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 18 Nov 2016 17:46:17 +0800 Subject: [PATCH 06/18] update size-changed for CCPageView --- cocos2d/core/components/CCPageView.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/components/CCPageView.js b/cocos2d/core/components/CCPageView.js index 11cf94fa07..4f256498d0 100644 --- a/cocos2d/core/components/CCPageView.js +++ b/cocos2d/core/components/CCPageView.js @@ -213,9 +213,7 @@ var PageView = cc.Class({ __preload: function () { this._super(); - if (this.sizeMode === SizeMode.Unified) { - this.node.on('size-changed', this._updateAllPagesSize, this); - } + this.node.on('size-changed', this._updateAllPagesSize, this); }, onEnable: function () { @@ -241,9 +239,7 @@ var PageView = cc.Class({ onDestroy: function() { this._super(); - if (this.sizeMode === SizeMode.Unified) { - this.node.off('size-changed', this._updateAllPagesSize, this); - } + this.node.off('size-changed', this._updateAllPagesSize, this); }, /** @@ -439,6 +435,9 @@ var PageView = cc.Class({ // 刷新所有页面的大小 _updateAllPagesSize: function () { + if (this.sizeMode !== SizeMode.Unified) { + return; + } var locPages = CC_EDITOR ? this.content.children : this._pages; var selfSize = this.node.getContentSize(); for (var i = 0, len = locPages.length; i < len; i++) { From 06764622db55f151f385e45425b6f501df30146e Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 18 Nov 2016 18:20:56 +0800 Subject: [PATCH 07/18] fix load bug for #fireball/issues/4739 --- cocos2d/core/load-pipeline/CCLoader.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index 6606914ea3..d9890ed7ef 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -38,6 +38,7 @@ function getXMLHttpRequest () { return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP'); } +var _sharedResources = []; var _sharedList = []; /** @@ -170,13 +171,17 @@ JS.mixin(CCLoader.prototype, { resources = resources ? [resources] : []; } + _sharedResources.length = resources.length; for (var i = 0; i < resources.length; ++i) { var url = resources[i].id || resources[i]; if (typeof url !== 'string') continue; var item = this.getItem(url); if (item) { - resources[i] = item; + _sharedResources[i] = item; + } + else { + _sharedResources[i] = resources[i]; } } @@ -205,7 +210,8 @@ JS.mixin(CCLoader.prototype, { }); }); LoadingItems.initQueueDeps(queue); - queue.append(resources); + queue.append(_sharedResources); + _sharedResources.length = 0; }, flowInDeps: function (owner, urlList, callback) { From 97771320eb52dba6af05ad6b6bfbe73a20cd429a Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 21 Nov 2016 11:22:39 +0800 Subject: [PATCH 08/18] fixed CCCollisionManager debug draw --- cocos2d/core/collider/CCCollisionManager.js | 34 ++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/cocos2d/core/collider/CCCollisionManager.js b/cocos2d/core/collider/CCCollisionManager.js index bb80dd50aa..45562ff295 100644 --- a/cocos2d/core/collider/CCCollisionManager.js +++ b/cocos2d/core/collider/CCCollisionManager.js @@ -319,11 +319,12 @@ var CollisionManager = cc.Class({ }, drawColliders: function () { - if (!this._enabledDebugDraw || !this._debugDrawer) { + var debugDrawer = this._debugDrawer; + if (!this._enabledDebugDraw || !debugDrawer) { return; } - this._debugDrawer.clear(); + debugDrawer.clear(); var colliders = this._colliders; @@ -331,16 +332,35 @@ var CollisionManager = cc.Class({ var collider = colliders[i]; if (collider instanceof cc.BoxCollider || collider instanceof cc.PolygonCollider) { - this._debugDrawer.drawPoly(collider.world.points.concat(), null, 1, cc.Color.WHITE); + var ps = collider.world.points; + if (ps.length > 0) { + debugDrawer.strokeColor = cc.Color.WHITE; + debugDrawer.moveTo(ps[0].x, ps[0].y); + for (var j = 1; j < ps.length; j++) { + debugDrawer.lineTo(ps[j].x, ps[j].y); + } + debugDrawer.close(); + debugDrawer.stroke(); + } } else if (collider instanceof cc.CircleCollider) { - this._debugDrawer.drawCircle(collider.world.position, collider.world.radius, 0, 30); + debugDrawer.circle(collider.world.position.x, collider.world.position.y, collider.world.radius); + debugDrawer.stroke(); } if (this.enabledDrawBoundingBox) { var aabb = collider.world.aabb; - var points = [cc.v2(aabb.xMin, aabb.yMin), cc.v2(aabb.xMin, aabb.yMax), cc.v2(aabb.xMax, aabb.yMax), cc.v2(aabb.xMax, aabb.yMin)]; - this._debugDrawer.drawPoly(points, null, 1, cc.Color.BLUE); + var ps = [cc.v2(aabb.xMin, aabb.yMin), cc.v2(aabb.xMin, aabb.yMax), cc.v2(aabb.xMax, aabb.yMax), cc.v2(aabb.xMax, aabb.yMin)]; + + if (ps.length > 0) { + debugDrawer.strokeColor = cc.Color.BLUE; + debugDrawer.moveTo(ps[0].x, ps[0].y); + for (var j = 1; j < ps.length; j++) { + debugDrawer.lineTo(ps[j].x, ps[j].y); + } + debugDrawer.close(); + debugDrawer.stroke(); + } } } }, @@ -367,7 +387,7 @@ cc.js.getset(CollisionManager.prototype, 'enabledDebugDraw', function (value) { if (value && !this._enabledDebugDraw) { if (!this._debugDrawer) { - this._debugDrawer = new cc.DrawNode(); + this._debugDrawer = new _ccsg.GraphicsNode(); this._debugDrawer.retain(); } From 138f4620ada0286c4db3bf187c690cc5d0db9bdd Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 21 Nov 2016 11:23:35 +0800 Subject: [PATCH 09/18] fixed graphics render in canvas moder --- cocos2d/core/graphics/graphics-canvas-cmd.js | 42 ++++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/cocos2d/core/graphics/graphics-canvas-cmd.js b/cocos2d/core/graphics/graphics-canvas-cmd.js index f36b74b023..d68ebfdebb 100644 --- a/cocos2d/core/graphics/graphics-canvas-cmd.js +++ b/cocos2d/core/graphics/graphics-canvas-cmd.js @@ -33,6 +33,14 @@ var CanvasRenderCmd = function (renderable) { _ccsg.Node.CanvasRenderCmd.call(this, renderable); this._needDraw = true; this.cmds = []; + + this.style = { + strokeStyle: 'black', + fillStyle: 'white', + lineCap: 'butt', + lineJoin: 'miter', + miterLimit: 10 + }; }; var _p = CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype); @@ -52,6 +60,13 @@ _p.rendering = function (ctx, scaleX, scaleY) { context.save(); context.scale(1, -1); + var style = this.style; + context.strokeStyle = style.strokeStyle; + context.fillStyle = style.fillStyle; + context.lineWidth = style.lineWidth; + context.lineJoin = style.lineJoin; + context.miterLimit = style.miterLimit; + var endPath = true; var cmds = this.cmds; for (var i = 0, l = cmds.length; i < l; i++) { @@ -80,45 +95,56 @@ _p.rendering = function (ctx, scaleX, scaleY) { // draw api Js.mixin(_p, { setStrokeColor: function (v) { - var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')'; - this.cmds.push(['strokeStyle', fillStyle]); + var strokeStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')'; + this.cmds.push(['strokeStyle', strokeStyle]); + this.style.strokeStyle = strokeStyle; }, setFillColor: function (v) { var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')'; this.cmds.push(['fillStyle', fillStyle]); + this.style.fillStyle = fillStyle; }, setLineWidth: function (v) { this.cmds.push(['lineWidth', v]); + this.style.lineWidth = v; }, setLineCap: function (v) { + var lineCap = 'butt'; if (v === LineCap.BUTT) { - this.cmds.push(['lineCap', 'butt']); + lineCap = 'butt'; } else if (v === LineCap.ROUND) { - this.cmds.push(['lineCap', 'round']); + lineCap = 'round'; } else if (v === LineCap.SQUARE) { - this.cmds.push(['lineCap', 'square']); + lineCap = 'square'; } + this.cmds.push(['lineCap', lineCap]); + this.style.lineCap = lineCap; }, setLineJoin: function (v) { + var lineJoin = 'bevel'; if (v === LineJoin.BEVEL) { - this.cmds.push(['lineJoin', 'bevel']); + lineJoin = 'bevel'; } else if (v === LineJoin.ROUND) { - this.cmds.push(['lineJoin', 'round']); + lineJoin = 'round'; } else if (v === LineJoin.MITER) { - this.cmds.push(['lineJoin', 'miter']); + lineJoin = 'miter'; } + + this.cmds.push(['lineJoin', lineJoin]); + this.style.lineJoin = lineJoin; }, setMiterLimit: function (v) { this.cmds.push(['miterLimit', v]); + this.style.miterLimit = v; }, // draw functions From 20493605ee11ee049316760eb7791287bf9350d8 Mon Sep 17 00:00:00 2001 From: zhangbin Date: Tue, 22 Nov 2016 10:26:27 +0800 Subject: [PATCH 10/18] Solve the error when use a same DragonBonesAsset twice. --- extensions/dragonbones/ArmatureDisplay.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/extensions/dragonbones/ArmatureDisplay.js b/extensions/dragonbones/ArmatureDisplay.js index 517add35f2..6d3e793b45 100644 --- a/extensions/dragonbones/ArmatureDisplay.js +++ b/extensions/dragonbones/ArmatureDisplay.js @@ -290,7 +290,7 @@ dragonBones.ArmatureDisplay = cc.Class({ _createSgNode: function () { if (this.dragonAsset && this.dragonAtlasAsset && this.armatureName) { - return this._factory.buildArmatureDisplay(this.armatureName); + return this._factory.buildArmatureDisplay(this.armatureName, this._dragonBonesData.name); } return null; }, @@ -311,10 +311,17 @@ dragonBones.ArmatureDisplay = cc.Class({ _parseDragonAsset : function() { if (this.dragonAsset) { + var jsonObj = JSON.parse(this.dragonAsset.dragonBonesJson); + var data = this._factory.getDragonBonesData(jsonObj.name); + if (data) { + // already added asset + this._dragonBonesData = data; + return; + } + if (CC_JSB) { this._dragonBonesData = this._factory.parseDragonBonesData(this.dragonAsset.dragonBonesJson); } else { - var jsonObj = JSON.parse(this.dragonAsset.dragonBonesJson); this._dragonBonesData = this._factory.parseDragonBonesData(jsonObj); } } From 05aa536a4c862e539840490358d911689e0fa882 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 23 Nov 2016 10:19:43 +0800 Subject: [PATCH 11/18] fix pageview buf for for #fireball/issues/4758 --- cocos2d/core/components/CCPageView.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/components/CCPageView.js b/cocos2d/core/components/CCPageView.js index 4f256498d0..0b64c5b355 100644 --- a/cocos2d/core/components/CCPageView.js +++ b/cocos2d/core/components/CCPageView.js @@ -528,24 +528,33 @@ var PageView = cc.Class({ return offset; }, - _updatePageIndex: function (moveOffset) { - var idx = 0; + _getDragDirection: function (moveOffset) { if (this.direction === Direction.Horizontal) { - idx += (moveOffset.x > 0 ? 1 : -1); + return (moveOffset.x > 0 ? 1 : -1); } else if (this.direction === Direction.Vertical) { // 由于滚动 Y 轴的原点在在右上角所以应该是小于 0 - idx += (moveOffset.y < 0 ? 1 : -1); + return (moveOffset.y < 0 ? 1 : -1); } - return this._curPageIdx + idx; }, _handleReleaseLogic: function(touch) { var bounceBackStarted = this._startBounceBackIfNeeded(); - if (!bounceBackStarted) { - var index = this._curPageIdx; - var moveOffset = cc.pSub(this._touchBeganPosition, this._touchEndPosition); - var nextIndex = this._updatePageIndex(moveOffset); + var index = this._curPageIdx, nextIndex = 0; + var moveOffset = cc.pSub(this._touchBeganPosition, this._touchEndPosition); + if (bounceBackStarted) { + if (this._getDragDirection(moveOffset) > 0) { + this._curPageIdx = this._pages.length - 1; + } + else { + this._curPageIdx = 0; + } + if (this.indicator) { + this.indicator._changedState(); + } + } + else { + nextIndex = index + this._getDragDirection(moveOffset); if (nextIndex < this._pages.length) { if (this._isScrollable(moveOffset, index, nextIndex)) { this.scrollToPage(nextIndex); From 7dde8471d9f09926b016afdd44ac33230145e054 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 23 Nov 2016 11:20:12 +0800 Subject: [PATCH 12/18] don't trigger loadTTF when ttf is not exists --- cocos2d/core/components/CCRichText.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index d5ffba3fdd..563fe29e2b 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -248,6 +248,8 @@ var RichText = cc.Class({ }, _onTTFLoaded: function () { + if(!this._getFontRawUrl()) return; + var self = this; var callback = function () { From baf4fbb3f33ebb7767682bc6d46ede879109df9f Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 23 Nov 2016 11:22:33 +0800 Subject: [PATCH 13/18] simplify code --- cocos2d/core/components/CCRichText.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index 563fe29e2b..51d0cc8005 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -248,7 +248,8 @@ var RichText = cc.Class({ }, _onTTFLoaded: function () { - if(!this._getFontRawUrl()) return; + var rawUrl = this._getFontRawUrl(); + if(!rawUrl) return; var self = this; @@ -257,7 +258,7 @@ var RichText = cc.Class({ self._updateRichText(); }; - cc.CustomFontLoader.loadTTF(this._getFontRawUrl(), callback); + cc.CustomFontLoader.loadTTF(rawUrl, callback); }, _measureText: function (styleIndex, string) { From d916e0d7f42c3f5c8dea4af4e5d1a4eace9d9866 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 23 Nov 2016 11:44:08 +0800 Subject: [PATCH 14/18] fix code and API err for fireball/issues/4722 --- cocos2d/actions/CCActionInterval.js | 2 +- cocos2d/core/CCNode.js | 2 +- cocos2d/core/base-nodes/CCSGNode.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js index 1b8440f3fd..2c49df9ce7 100644 --- a/cocos2d/actions/CCActionInterval.js +++ b/cocos2d/actions/CCActionInterval.js @@ -126,7 +126,7 @@ cc.ActionInterval = cc.FiniteTimeAction.extend({ * @param {Object} easeObj * @returns {ActionInterval} * @example - * action.easeing(cc.easeIn(3.0)); + * action.easing(cc.easeIn(3.0)); */ easing: function (easeObj) { if (this._easeList) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index dad4fdfe9a..0bb99383f1 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1440,7 +1440,7 @@ var Node = cc.Class({ * cc.log("Running Action Count: " + count); */ getNumberOfRunningActions: function () { - cc.director.getActionManager().numberOfRunningActionsInTarget(this); + return cc.director.getActionManager().getNumberOfRunningActionsInTarget(this); }, _retainAction: function (action) { diff --git a/cocos2d/core/base-nodes/CCSGNode.js b/cocos2d/core/base-nodes/CCSGNode.js index db0937e745..1dc88c19e3 100644 --- a/cocos2d/core/base-nodes/CCSGNode.js +++ b/cocos2d/core/base-nodes/CCSGNode.js @@ -1494,7 +1494,7 @@ _ccsg.Node = cc.Class({ * @return {Number} The number of actions that are running plus the ones that are schedule to run */ getNumberOfRunningActions: function () { - return this.actionManager.numberOfRunningActionsInTarget(this); + return this.actionManager.getNumberOfRunningActionsInTarget(this); }, // _ccsg.Node - Callbacks From f82062160a3ce13244ea7422a5cfb2acd443c5de Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 23 Nov 2016 14:46:32 +0800 Subject: [PATCH 15/18] fix label jsb resize height dimensions issue --- cocos2d/core/components/CCLabel.js | 10 +--------- jsb/jsb-label.js | 3 +++ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index 03a58be889..8d9fafdf5c 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -504,17 +504,9 @@ var Label = cc.Class({ _updateNodeSize: function () { var initialized = this._sgNode && this._sgNode.parent; if (initialized) { - if (this.overflow === Overflow.NONE) { + if (this.overflow === Overflow.NONE || this.overflow === Overflow.RESIZE_HEIGHT) { this.node.setContentSize(this._sgNode.getContentSize()); } - - if(this.overflow === Overflow.RESIZE_HEIGHT) { - //call this.node.getContentSize actually sync the node size with sgNode - //such that it won't trigger setDimensions method in jsb - var originalSize = this.node.getContentSize(); - var newSize = this._sgNode.getContentSize(); - this.node.setContentSize(cc.size(originalSize.width, newSize.height)); - } } } }); diff --git a/jsb/jsb-label.js b/jsb/jsb-label.js index c4b51674b9..b3e61f75ac 100644 --- a/jsb/jsb-label.js +++ b/jsb/jsb-label.js @@ -134,6 +134,7 @@ jsbLabel.prototype.getTTFConfig = function () { return this._ttfConfig; }; +jsbLabel.prototype._setContentSize = jsbLabel.prototype.setContentSize; jsbLabel.prototype.setContentSize = function (size, height) { var newWidth = (typeof size.width === 'number') ? size.width : size; var newHeight = (typeof size.height === 'number') ? size.height : height; @@ -141,6 +142,8 @@ jsbLabel.prototype.setContentSize = function (size, height) { if(this.getOverflow() === cc.Label.Overflow.NONE) { newWidth = 0; newHeight = 0; + } else { + this._setContentSize(newWidth, newHeight); } this.setDimensions(newWidth, newHeight); }; From a2e39dc959c6c8a76fe52bab0adafc190432c2a0 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 23 Nov 2016 17:47:27 +0800 Subject: [PATCH 16/18] add tooltip for CCParticleSystem --- cocos2d/particle/CCParticleSystem.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index b8227949e4..86c88cff68 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -101,7 +101,8 @@ var properties = { } cc.engine.repaintInEditMode(); }, - animatable: false + animatable: false, + tooltip: 'i18n:COMPONENT.particle_system.preview' }, /** @@ -134,7 +135,8 @@ var properties = { } } }, - animatable: false + animatable: false, + tooltip: 'i18n:COMPONENT.particle_system.custom' }, /** @@ -167,7 +169,8 @@ var properties = { } }, animatable: false, - url: cc.ParticleAsset + url: cc.ParticleAsset, + tooltip: 'i18n:COMPONENT.particle_system.file' }, /** @@ -191,7 +194,8 @@ var properties = { this._applyFile(); } }, - url: cc.Texture2D + url: cc.Texture2D, + tooltip: 'i18n:COMPONENT.particle_system.texture' }, /** @@ -206,7 +210,8 @@ var properties = { set: function (value) { this._sgNode.particleCount = value; }, - visible: false + visible: false, + tooltip: 'i18n:COMPONENT.particle_system.particleCount' }, /** @@ -226,7 +231,8 @@ var properties = { this._sgNode.setBlendFunc(this._blendFunc); }, animatable: false, - type:BlendFactor + type:BlendFactor, + tooltip: 'i18n:COMPONENT.particle_system.srcBlendFactor' }, /** @@ -246,7 +252,8 @@ var properties = { this._sgNode.setBlendFunc(this._blendFunc); }, animatable: false, - type: BlendFactor + type: BlendFactor, + tooltip: 'i18n:COMPONENT.particle_system.dstBlendFactor' }, /** @@ -276,7 +283,8 @@ var properties = { } } }, - animatable: false + animatable: false, + tooltip: 'i18n:COMPONENT.particle_system.autoRemoveOnFinish' }, /** From ae26a61ead0dc5970c74c1fe7bfc3b74c584e671 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 25 Nov 2016 10:16:20 +0800 Subject: [PATCH 17/18] fix callback for loading sprite frame --- cocos2d/core/components/CCSprite.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 15626acdf3..1da9e06eff 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -538,7 +538,10 @@ var Sprite = cc.Class({ _onSpriteFrameLoaded: function (event) { var self = this; - var sgNode = this._sgNode; + if (!self.isValid) { + return; + } + var sgNode = self._sgNode; sgNode.setSpriteFrame(self._spriteFrame); self._applyCapInset(); self._applySpriteSize(); From 5a9dba25d1a92c04ed7e0f9b216de5705e617a33 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 25 Nov 2016 10:56:07 +0800 Subject: [PATCH 18/18] fix cc.Node:getActionByTag returns undefined for engine/issues/1300 --- cocos2d/core/CCNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 0bb99383f1..4ba8bebaa0 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1418,7 +1418,7 @@ var Node = cc.Class({ cc.log(cc._LogInfos.Node.getActionByTag); return null; } - cc.director.getActionManager().getActionByTag(tag, this); + return cc.director.getActionManager().getActionByTag(tag, this); }, /**