From da5c70c2337e6aa18978a3b903cfa9abecdb0e14 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 17 Jan 2018 11:31:42 +0800 Subject: [PATCH] Fix mask hit test --- cocos2d/core/components/CCMask.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js index b06f43ba36..cd378984d8 100644 --- a/cocos2d/core/components/CCMask.js +++ b/cocos2d/core/components/CCMask.js @@ -297,13 +297,12 @@ let Mask = cc.Class({ _hitTest: function (point) { let node = this.node; + let size = node.getContentSize(), + w = size.width, + h = size.height; node.getWorldMatrix(_mat4_temp); if (this.type === MaskType.RECT || this.type === MaskType.IMAGE_STENCIL) { - let size = node.getContentSize(), - w = size.width, - h = size.height; - _rect_temp.x = -node.anchorX * w, _rect_temp.y = -node.anchorX * h; _rect_temp.width = w; @@ -318,8 +317,9 @@ let Mask = cc.Class({ return left >= 0 && right >= 0 && top >= 0 && bottom >= 0; } else if (this.type === MaskType.ELLIPSE) { + let rx = w / 2, ry = h / 2; let px = point.x - _mat4_temp.m12, py = point.y - _mat4_temp.m13; - return px * px / (a * a) + py * py / (b * b) < 1; + return px * px / (rx * rx) + py * py / (ry * ry) < 1; } },