From 02e10f089925a2d5d6548400ca17749792f68d3a Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 29 Aug 2016 18:57:56 +0800 Subject: [PATCH 1/5] fix asset-watcher --- cocos2d/core/components/CCComponent.js | 7 ++++--- cocos2d/core/components/CCSprite.js | 13 ++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index 0c0d70444c..f278c7ca24 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -236,9 +236,10 @@ var Component = cc.Class({ name: 'cc.Component', extends: cc.Object, - ctor: (CC_EDITOR && window._Scene && _Scene.AssetsWatcher) ? function () { - _Scene.AssetsWatcher.initComponent(this); - + ctor: CC_EDITOR ? function () { + if (window._Scene && _Scene.AssetsWatcher) { + _Scene.AssetsWatcher.initComponent(this); + } // Support for Scheduler this.__instanceId = cc.ClassManager.getNewInstanceId(); } : function () { diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index 055b2fffbe..0dd40826b0 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -163,10 +163,17 @@ var Sprite = cc.Class({ return this._spriteFrame; }, set: function (value, force) { - if (this._spriteFrame === value) { - return; - } var lastSprite = this._spriteFrame; + if (CC_EDITOR) { + if (!force && ((lastSprite && lastSprite._uuid) === (value && value._uuid))) { + return; + } + } + else { + if (lastSprite === value) { + return; + } + } this._spriteFrame = value; this._applySpriteFrame(lastSprite); if (CC_EDITOR) { From e467bf1f58f1d11cd3405d91651f97332a4ca068 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 31 Aug 2016 09:29:46 +0800 Subject: [PATCH 2/5] add getAllTextures for CCTextureCache for fireball/issues/2836 --- cocos2d/core/platform/CCView.js | 5 ++--- cocos2d/core/textures/CCTextureCache.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/platform/CCView.js b/cocos2d/core/platform/CCView.js index 86df5e28b0..646b8a3d49 100644 --- a/cocos2d/core/platform/CCView.js +++ b/cocos2d/core/platform/CCView.js @@ -151,7 +151,7 @@ var View = cc._Class.extend({ __resizeWithBrowserSize: false, _isAdjustViewPort: true, _targetDensityDPI: null, - _antiAliasEnabled: false, + _antiAliasEnabled: true, /** * Constructor of View @@ -184,7 +184,6 @@ var View = cc._Class.extend({ _t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH); _t._targetDensityDPI = cc.macro.DENSITYDPI_HIGH; - _t.enableAntiAlias(true); }, // Resize helper functions @@ -469,7 +468,7 @@ var View = cc._Class.extend({ * !#en Returns whether the current enable on anti-alias * !#zh 返回当前是否抗锯齿 * @method isAntiAliasEnabled - * @param {Boolean} enabled - Pass false to make pixel art sharp. + * @return {Boolean} */ isAntiAliasEnabled: function () { return this._antiAliasEnabled; diff --git a/cocos2d/core/textures/CCTextureCache.js b/cocos2d/core/textures/CCTextureCache.js index 54bd675522..ac6650163b 100644 --- a/cocos2d/core/textures/CCTextureCache.js +++ b/cocos2d/core/textures/CCTextureCache.js @@ -125,6 +125,21 @@ var textureCache = /** @lends cc.textureCache# */{ return this._textureColorsCache[key]; }, + /** + * #en get all textures + * #zh 获取所有贴图 + * @method getAllTextures + * @return {Texture2D[]} + */ + getAllTextures: function () { + var texs = []; + for (var key in this._textures) { + var item = this._textures[key]; + texs.push(item); + } + return texs; + }, + /** *

Purges the dictionary of loaded textures.
* Call this method if you receive the "Memory Warning"
From 8bc2220233f4b8138c2209c70adeae2cc29cf815 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 10 Aug 2016 15:51:53 +0800 Subject: [PATCH 3/5] fix editbox maxLength on PC --- cocos2d/core/editbox/CCSGEditBox.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 82647dd0c0..3d779c8a65 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -581,10 +581,18 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; tmpEdTxt.addEventListener('input', function () { var editBox = thisPointer._editBox; + + + if (this.value.length > this.maxLength) { + this.value = this.value.slice(0, this.maxLength); + } + if (editBox._delegate && editBox._delegate.editBoxTextChanged) { - editBox._text = this.value; - thisPointer._updateEditBoxContentStyle(); - editBox._delegate.editBoxTextChanged(editBox, editBox._text); + if (editBox._text.toLowerCase() !== this.value.toLowerCase()) { + editBox._text = this.value; + thisPointer._updateEditBoxContentStyle(); + editBox._delegate.editBoxTextChanged(editBox, editBox._text); + } } }); tmpEdTxt.addEventListener('keypress', function (e) { @@ -597,6 +605,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; this.style.fontSize = editBox._placeholderFontSize + 'px'; this.style.color = cc.colorToHex(editBox._placeholderColor); } + editBox._text = this.value; thisPointer._updateEditBoxContentStyle(); thisPointer.hidden(); @@ -670,11 +679,17 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; tmpEdTxt.style.className = "cocosEditBox"; tmpEdTxt.addEventListener('input', function () { + if (this.value.length > this.maxLength) { + this.value = this.value.slice(0, this.maxLength); + } + var editBox = thisPointer._editBox; if (editBox._delegate && editBox._delegate.editBoxTextChanged) { - editBox._text = this.value; - thisPointer._updateEditBoxContentStyle(); - editBox._delegate.editBoxTextChanged(editBox, editBox._text); + if(editBox._text.toLowerCase() !== this.value.toLowerCase()) { + editBox._text = this.value; + thisPointer._updateEditBoxContentStyle(); + editBox._delegate.editBoxTextChanged(editBox, editBox._text); + } } }); From ca69aaf1fed1c646fc2ad9f6818fb76cd595e3d9 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 31 Aug 2016 16:12:30 +0800 Subject: [PATCH 4/5] add touch up event to scrollview --- cocos2d/core/components/CCScrollView.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 33b34d1fc6..5f27b68f40 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -103,7 +103,13 @@ var EventType = cc.Enum({ * !#zh 滚动视图滚动滚动结束的时候发出的事件 * @property {Number} AUTOSCROLL_ENDED */ - AUTOSCROLL_ENDED : 9 + AUTOSCROLL_ENDED : 9, + /** + * !#en The event emmitted when user release the touch + * !#zh 当用户松手的时候会发出一个事件 + * @property {Number} TOUCH_UP + */ + TOUCH_UP : 10 }); /** @@ -885,6 +891,7 @@ var ScrollView = cc.Class({ if (this.content) { this._handleReleaseLogic(touch); } + this._dispatchEvent(EventType.TOUCH_UP); if (this._touchMoved) { event.stopPropagation(); } From e43fe1d47f27155a9d34380ab0add01e5804bbd4 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 31 Aug 2016 16:27:13 +0800 Subject: [PATCH 5/5] fix scrollview enable event handling --- cocos2d/core/components/CCScrollView.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 33b34d1fc6..0bc2a0c41c 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -698,6 +698,8 @@ var ScrollView = cc.Class({ }, _onMouseWheel: function(event) { + if (!this.enabledInHierarchy) return; + var deltaMove = cc.p(0, 0); var wheelPrecision = 1.0 / 40; if(CC_JSB) { @@ -847,6 +849,8 @@ var ScrollView = cc.Class({ // touch event handler _onTouchBegan: function(event) { + if (!this.enabledInHierarchy) return; + var touch = event.touch; if (this.content) { this._handlePressLogic(touch); @@ -855,6 +859,8 @@ var ScrollView = cc.Class({ }, _onTouchMoved: function(event) { + if (!this.enabledInHierarchy) return; + var touch = event.touch; if (this.content) { this._handleMoveLogic(touch); @@ -881,6 +887,8 @@ var ScrollView = cc.Class({ }, _onTouchEnded: function(event) { + if (!this.enabledInHierarchy) return; + var touch = event.touch; if (this.content) { this._handleReleaseLogic(touch); @@ -890,6 +898,8 @@ var ScrollView = cc.Class({ } }, _onTouchCancelled: function(event) { + if (!this.enabledInHierarchy) return; + // Filte touch cancel event send from self if (!event.simulate) { var touch = event.touch;