From d46a4db8cb114afb225e2c055e4b586a24c96f16 Mon Sep 17 00:00:00 2001 From: SmallMain Date: Sat, 25 Jun 2022 01:03:18 +0800 Subject: [PATCH] =?UTF-8?q?[engine]=20=E5=A4=9A=E7=BA=B9=E7=90=86=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E3=80=81=E5=8A=A8=E6=80=81=E5=9B=BE=E9=9B=86=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=BC=80=E5=85=B3=E6=97=B6=E4=B8=BB=E5=8A=A8=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=B8=B2=E6=9F=93=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/cocos2d/core/components/CCLabel.js | 9 +++++++++ .../cocos2d/core/components/CCMotionStreak.js | 12 ++++++++++++ engine/cocos2d/core/components/CCSprite.js | 8 ++++++++ engine/extensions/spine/Skeleton.js | 18 ++++++++++++++++-- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/engine/cocos2d/core/components/CCLabel.js b/engine/cocos2d/core/components/CCLabel.js index cd66e724..9d222191 100644 --- a/engine/cocos2d/core/components/CCLabel.js +++ b/engine/cocos2d/core/components/CCLabel.js @@ -586,15 +586,24 @@ let Label = cc.Class({ autoSwitchMaterial: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, + notify(oldValue) { + if (this.autoSwitchMaterial === oldValue) return; + this.setVertsDirty(); + }, }, allowDynamicAtlas: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, + notify(oldValue) { + if (this.allowDynamicAtlas === oldValue) return; + this.setVertsDirty(); + }, }, enableRetina: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, notify(oldValue) { + if (this.enableRetina === oldValue) return; this.setVertsDirty(); } }, diff --git a/engine/cocos2d/core/components/CCMotionStreak.js b/engine/cocos2d/core/components/CCMotionStreak.js index dca7d618..91b6153f 100644 --- a/engine/cocos2d/core/components/CCMotionStreak.js +++ b/engine/cocos2d/core/components/CCMotionStreak.js @@ -219,9 +219,21 @@ var MotionStreak = cc.Class({ autoSwitchMaterial: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, + notify(oldValue) { + if (this.autoSwitchMaterial === oldValue) return; + this.setVertsDirty(); + }, }, }, + setVertsDirty() { + // 自动切换材质 + this._checkSwitchMaterial(); + + this._updateMaterial(); + this._super(); + }, + __preload() { this._super(); this._checkSwitchMaterial(); diff --git a/engine/cocos2d/core/components/CCSprite.js b/engine/cocos2d/core/components/CCSprite.js index 5bbc32af..051c7617 100644 --- a/engine/cocos2d/core/components/CCSprite.js +++ b/engine/cocos2d/core/components/CCSprite.js @@ -391,10 +391,18 @@ var Sprite = cc.Class({ autoSwitchMaterial: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, + notify(oldValue) { + if (this.autoSwitchMaterial === oldValue) return; + this.setVertsDirty(); + }, }, allowDynamicAtlas: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, + notify(oldValue) { + if (this.allowDynamicAtlas === oldValue) return; + this.setVertsDirty(); + }, }, }, diff --git a/engine/extensions/spine/Skeleton.js b/engine/extensions/spine/Skeleton.js index 2cb576ff..ecfb5cac 100644 --- a/engine/extensions/spine/Skeleton.js +++ b/engine/extensions/spine/Skeleton.js @@ -435,10 +435,18 @@ sp.Skeleton = cc.Class({ autoSwitchMaterial: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, + notify(oldValue) { + if (this.autoSwitchMaterial === oldValue) return; + this.setVertsDirty(); + }, }, allowDynamicAtlas: { type: RenderComponent.EnableType, default: RenderComponent.EnableType.GLOBAL, + notify(oldValue) { + if (this.allowDynamicAtlas === oldValue) return; + this.setVertsDirty(); + }, }, }, @@ -458,6 +466,13 @@ sp.Skeleton = cc.Class({ this._dataDirty = true; }, + setVertsDirty() { + this._dataDirty = true; + this.invalidAnimationCache(); + this._materialCache = {}; + this._super(); + }, + // override base class _getDefaultMaterial to modify default material _getDefaultMaterial () { return cc.Material.getBuiltinMaterial('2d-spine'); @@ -1010,8 +1025,7 @@ sp.Skeleton = cc.Class({ attachment.setRegion(region); attachment.updateOffset(); } - this._dataDirty = true; - this.invalidAnimationCache(); + this.setVertsDirty(); return true; } return false;