From 63c3bdc31e994341ab3ba03fc663728d576ba414 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Mon, 3 Jun 2019 19:25:09 +0800 Subject: [PATCH] fix button sprite bidirectional sync and mask options error (#4544) --- cocos/3d/ui/assembler/mask/stencil-manager.ts | 4 ++++ cocos/3d/ui/components/button-component.ts | 18 ++++++++---------- cocos/scene-graph/node.ts | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cocos/3d/ui/assembler/mask/stencil-manager.ts b/cocos/3d/ui/assembler/mask/stencil-manager.ts index b1d4fc4e76..d4466c264e 100644 --- a/cocos/3d/ui/assembler/mask/stencil-manager.ts +++ b/cocos/3d/ui/assembler/mask/stencil-manager.ts @@ -121,6 +121,10 @@ export class StencilManager { const pattern = this._stencilPattern; if (this.stage === Stage.DISABLED) { pattern.stencilTest = false; + pattern.func = GFXComparisonFunc.ALWAYS; + pattern.failOp = GFXStencilOp.KEEP; + pattern.stencilMask = pattern.writeMask = 0xffffffff; + pattern.ref = 1; } else { pattern.stencilTest = true; if (this.stage === Stage.ENABLED) { diff --git a/cocos/3d/ui/components/button-component.ts b/cocos/3d/ui/components/button-component.ts index c72543078e..ea49fd2af8 100644 --- a/cocos/3d/ui/components/button-component.ts +++ b/cocos/3d/ui/components/button-component.ts @@ -470,14 +470,13 @@ export class ButtonComponent extends Component { // if (!CC_EDITOR) { this._registerEvent(); + } else { + this.node.on('spriteframe-changed', (comp: SpriteComponent) => { + if (this._transition === Transition.SPRITE) { + this._normalSprite = comp.spriteFrame; + } + }, this); } - // else { - // this.node.on('spriteframe-changed', (comp) => { - // if (this._transition === Transition.SPRITE) { - // this._normalSprite = comp.spriteFrame; - // } - // }, this); - // } } public onDisable () { @@ -491,10 +490,9 @@ export class ButtonComponent extends Component { this.node.off(SystemEventType.MOUSE_ENTER, this._onMouseMoveIn, this); this.node.off(SystemEventType.MOUSE_LEAVE, this._onMouseMoveOut, this); + } else { + this.node.off('spriteframe-changed'); } - // else { - // this.node.off('spriteframe-changed'); - // } } public update (dt: number) { diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 78dc44cdd1..2111ab5acc 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -857,7 +857,7 @@ class Node extends BaseNode { this._eventProcessor.on(type, callback, target, useCapture); } - public off (type: string, callback: Function, target?: Object, useCapture?: any) { + public off (type: string, callback?: Function, target?: Object, useCapture?: any) { this._eventProcessor.off(type, callback, target, useCapture); const hasListeners = this._eventProcessor.hasEventListener(type);