From e87d87b53633454c5de21864b82f267a4d97686b Mon Sep 17 00:00:00 2001 From: Lu Ching Wen Date: Fri, 4 Nov 2016 11:46:30 +0800 Subject: [PATCH 1/2] Fix low performance issue fix low performance issue when you enable mousemove event. --- mouse/libsrc/src/MouseDelegate.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mouse/libsrc/src/MouseDelegate.ts b/mouse/libsrc/src/MouseDelegate.ts index ede5a23e..daba747c 100644 --- a/mouse/libsrc/src/MouseDelegate.ts +++ b/mouse/libsrc/src/MouseDelegate.ts @@ -76,12 +76,20 @@ module mouse { export var enable = function (stage:egret.Stage) { isPC = egret.Capabilities.os == "Windows PC" || egret.Capabilities.os == "Mac OS"; stageObj = stage; - var check = function (x:number, y:number) { + let preMouseX = NaN; + let preMouseY = NaN; + var check = function (x:number, y:number, hitTestTarget?:egret.DisplayObject) { if (currentTarget && !currentTarget.$stage) { dispatch(MouseEvent.MOUSE_OUT, true, x, y); dispatch(MouseEvent.ROLL_OUT, false, x, y); currentTarget = null; } + if(preMouseX == x && preMouseY == y) { + return; + }else { + preMouseX = x; + preMouseY = y; + } var result = stage.$hitTest(x, y); if (result != null && result != stage) { if (!currentTarget) { @@ -115,13 +123,14 @@ module mouse { mouseY = y; onTouchMove.call(this, x, y, touchPointID); if(mouseMoveEnabled) { - var target = stageObj.$hitTest(x, y); + var result = stageObj.$hitTest(x, y); + var target = result; if (!target) { target = stageObj; } egret.TouchEvent.dispatchTouchEvent(target, MouseEvent.MOUSE_MOVE, true, true, x, y, touchPointID, true); } - check(x, y); + check(x, y, result); }; var onTouchBegin = egret.sys.TouchHandler.prototype.onTouchBegin; egret.sys.TouchHandler.prototype.onTouchBegin = function (x:number, y:number, touchPointID:number) { @@ -173,4 +182,4 @@ module mouse { export var setMouseMoveEnabled = function (enabled:boolean) { mouseMoveEnabled = enabled; } -} \ No newline at end of file +} From 8b4b83a4fefb51014e7d6fc82384fe953f5a4cea Mon Sep 17 00:00:00 2001 From: Lu Ching Wen Date: Fri, 4 Nov 2016 11:48:40 +0800 Subject: [PATCH 2/2] Update MouseDelegate.ts --- mouse/libsrc/src/MouseDelegate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mouse/libsrc/src/MouseDelegate.ts b/mouse/libsrc/src/MouseDelegate.ts index daba747c..c99c0f21 100644 --- a/mouse/libsrc/src/MouseDelegate.ts +++ b/mouse/libsrc/src/MouseDelegate.ts @@ -90,7 +90,7 @@ module mouse { preMouseX = x; preMouseY = y; } - var result = stage.$hitTest(x, y); + var result = hitTestTarget || stage.$hitTest(x, y); if (result != null && result != stage) { if (!currentTarget) { currentTarget = result;