From a14c457602858a57913cc1fa051f70bd2d603cfd Mon Sep 17 00:00:00 2001 From: SmallMain Date: Thu, 21 Nov 2024 18:21:04 +0800 Subject: [PATCH] =?UTF-8?q?[engine]=20=E4=BC=98=E5=8C=96=20cc.Button=20?= =?UTF-8?q?=E6=80=A7=E8=83=BD=EF=BC=8Cinteractable=20=E6=9C=AA=E6=94=B9?= =?UTF-8?q?=E5=8F=98=E6=97=B6=E4=B8=8D=E8=BF=9B=E8=A1=8C=E6=9D=90=E8=B4=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2=EF=BC=8C=E5=87=8F=E5=B0=91=20update=20?= =?UTF-8?q?=E6=97=B6=E9=9C=80=E6=89=A7=E8=A1=8C=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/cocos2d/core/components/CCButton.js | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/engine/cocos2d/core/components/CCButton.js b/engine/cocos2d/core/components/CCButton.js index 8f47c10a..609a419b 100644 --- a/engine/cocos2d/core/components/CCButton.js +++ b/engine/cocos2d/core/components/CCButton.js @@ -71,7 +71,7 @@ const State = cc.Enum({ /** * !#en * Button component. Can be pressed or clicked. Button has 4 Transition types: - * + * * - Button.Transition.NONE // Button will do nothing * - Button.Transition.COLOR // Button will change target's color * - Button.Transition.SPRITE // Button will change target Sprite's sprite @@ -79,12 +79,12 @@ const State = cc.Enum({ * * The button can bind events (but you must be on the button's node to bind events).
* The following events can be triggered on all platforms. - * + * * - cc.Node.EventType.TOUCH_START // Press * - cc.Node.EventType.TOUCH_MOVE // After pressing and moving * - cc.Node.EventType.TOUCH_END // After pressing and releasing * - cc.Node.EventType.TOUCH_CANCEL // Press to cancel - * + * * The following events are only triggered on the PC platform: * * - cc.Node.EventType.MOUSE_DOWN @@ -100,7 +100,7 @@ const State = cc.Enum({ * 按钮组件。可以被按下,或者点击。 * * 按钮可以通过修改 Transition 来设置按钮状态过渡的方式: - * + * * - Button.Transition.NONE // 不做任何过渡 * - Button.Transition.COLOR // 进行颜色之间过渡 * - Button.Transition.SPRITE // 进行精灵之间过渡 @@ -108,21 +108,21 @@ const State = cc.Enum({ * * 按钮可以绑定事件(但是必须要在按钮的 Node 上才能绑定事件):
* 以下事件可以在全平台上都触发: - * + * * - cc.Node.EventType.TOUCH_START // 按下时事件 * - cc.Node.EventType.TOUCH_MOVE // 按住移动后事件 * - cc.Node.EventType.TOUCH_END // 按下后松开后事件 * - cc.Node.EventType.TOUCH_CANCEL // 按下取消事件 - * + * * 以下事件只在 PC 平台上触发: - * + * * - cc.Node.EventType.MOUSE_DOWN // 鼠标按下时事件 * - cc.Node.EventType.MOUSE_MOVE // 鼠标按住移动后事件 * - cc.Node.EventType.MOUSE_ENTER // 鼠标进入目标事件 * - cc.Node.EventType.MOUSE_LEAVE // 鼠标离开目标事件 * - cc.Node.EventType.MOUSE_UP // 鼠标松开事件 * - cc.Node.EventType.MOUSE_WHEEL // 鼠标滚轮事件 - * + * * 用户可以通过获取 __点击事件__ 回调函数的参数 event 的 target 属性获取当前点击对象。 * @class Button * @extends Component @@ -184,11 +184,13 @@ let Button = cc.Class({ interactable: { default: true, tooltip: CC_DEV && 'i18n:COMPONENT.button.interactable', - notify () { - this._updateState(); + notify (oldValue) { + if (oldValue !== this.interactable) { + this._updateState(); - if (!this.interactable) { - this._resetState(); + if (!this.interactable) { + this._resetState(); + } } }, animatable: false @@ -469,7 +471,7 @@ let Button = cc.Class({ if (this.disabledSprite) { this.disabledSprite.ensureLoadTexture(); } - + if (!CC_EDITOR) { this._registerNodeEvent(); } @@ -581,7 +583,6 @@ let Button = cc.Class({ }, update (dt) { - let target = this._getTarget(); if (this._transitionFinished) return; if (this.transition !== Transition.COLOR && this.transition !== Transition.SCALE) return; @@ -602,6 +603,7 @@ let Button = cc.Class({ } // Skip if _originalScale is invalid else if (this.transition === Transition.SCALE && this._originalScale) { + let target = this._getTarget(); target.scale = this._fromScale.lerp(this._toScale, ratio); }