From d4262671786898f63d5a4ab81bb0c4ea8aa49ea8 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 26 Feb 2016 14:59:49 +0800 Subject: [PATCH 1/2] Fix hover issue when two node located side by side --- cocos2d/core/CCNode.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 55c2432f28..cbc39862b6 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -128,6 +128,8 @@ var _mouseEvents = [ EventType.MOUSE_WHEEL, ]; +var currentHovered = null; + var _touchStartHandler = function (touch, event) { var pos = touch.getLocation(); var node = this.owner; @@ -179,6 +181,13 @@ var _mouseMoveHandler = function (event) { if (node._hitTest(pos, this)) { event.stopPropagation(); if (!this._previousIn) { + // Fix issue when hover node switched, previous hovered node won't get MOUSE_LEAVE notification + if (currentHovered) { + event.type = EventType.MOUSE_LEAVE; + currentHovered.owner.dispatchEvent(event); + currentHovered._previousIn = false; + } + currentHovered = this; event.type = EventType.MOUSE_ENTER; node.dispatchEvent(event); this._previousIn = true; @@ -190,6 +199,7 @@ var _mouseMoveHandler = function (event) { event.type = EventType.MOUSE_LEAVE; node.dispatchEvent(event); this._previousIn = false; + currentHovered = null; } }; var _mouseUpHandler = function (event) { From d4bf10836fb14c4ddbfa508e2adbfd5e61d38d57 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 26 Feb 2016 16:29:07 +0800 Subject: [PATCH 2/2] Fix callbacks handler removing issue --- cocos2d/core/platform/callbacks-invoker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/platform/callbacks-invoker.js b/cocos2d/core/platform/callbacks-invoker.js index 214adc972d..2e2c742e41 100644 --- a/cocos2d/core/platform/callbacks-invoker.js +++ b/cocos2d/core/platform/callbacks-invoker.js @@ -179,6 +179,7 @@ if (CC_TEST) { * @param {any} [p5] */ CallbacksInvoker.prototype.invoke = function (key, p1, p2, p3, p4, p5) { + this._toRemove.length = 0; this._invoking = key; var list = this._callbackTable[key], i; if (list) { @@ -205,7 +206,7 @@ CallbacksInvoker.prototype.invoke = function (key, p1, p2, p3, p4, p5) { // Delay removing for (i = 0; i < this._toRemove.length; ++i) { var toRemove = this._toRemove[i]; - this.remove(this._invoking, toRemove[0], toRemove[1]); + this.remove(key, toRemove[0], toRemove[1]); } this._toRemove.length = 0; if (this._toRemoveAll) {