diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 5c9a045..0fcc454 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -742,9 +742,8 @@ { interactiveParent = false; } - - // it has a mask! Then lets hit test that before continuing.. - if (hitTest && displayObject._mask) + // it has a mask! Then lets hit test that before continuing + else if (hitTest && displayObject._mask) { if (!displayObject._mask.containsPoint(point)) { @@ -752,15 +751,6 @@ } } - // it has a filterArea! Same as mask but easier, its a rectangle - if (hitTest && displayObject.filterArea) - { - if (!displayObject.filterArea.contains(point.x, point.y)) - { - hitTest = false; - } - } - // ** FREE TIP **! If an object is not interactive or has no buttons in it // (such as a game scene!) set interactiveChildren to false for that displayObject. // This will allow pixi to completely ignore and bypass checking the displayObjects children. diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 5c9a045..0fcc454 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -742,9 +742,8 @@ { interactiveParent = false; } - - // it has a mask! Then lets hit test that before continuing.. - if (hitTest && displayObject._mask) + // it has a mask! Then lets hit test that before continuing + else if (hitTest && displayObject._mask) { if (!displayObject._mask.containsPoint(point)) { @@ -752,15 +751,6 @@ } } - // it has a filterArea! Same as mask but easier, its a rectangle - if (hitTest && displayObject.filterArea) - { - if (!displayObject.filterArea.contains(point.x, point.y)) - { - hitTest = false; - } - } - // ** FREE TIP **! If an object is not interactive or has no buttons in it // (such as a game scene!) set interactiveChildren to false for that displayObject. // This will allow pixi to completely ignore and bypass checking the displayObjects children. diff --git a/test/core/Graphics.js b/test/core/Graphics.js index 98c7584..c8836f5 100644 --- a/test/core/Graphics.js +++ b/test/core/Graphics.js @@ -1,5 +1,7 @@ 'use strict'; +const MockPointer = require('../interaction/MockPointer'); + describe('PIXI.Graphics', function () { describe('constructor', function () @@ -218,4 +220,114 @@ expect(spy).to.have.been.calledOnce; }); }); + + describe('mask', function () + { + it('should trigger interaction callback when no mask present', function () + { + const stage = new PIXI.Container(); + const pointer = new MockPointer(stage); + const graphics = new PIXI.Graphics(); + const mask = new PIXI.Graphics(); + const spy = sinon.spy(); + + graphics.interactive = true; + graphics.beginFill(0xFF0000); + graphics.drawRect(0, 0, 50, 50); + graphics.on('click', spy); + stage.addChild(graphics); + mask.beginFill(); + mask.drawRect(0, 0, 50, 50); + graphics.mask = mask; + + pointer.click(10, 10); + + expect(spy).to.have.been.calledOnce; + }); + it('should trigger interaction callback when mask uses beginFill', function () + { + const stage = new PIXI.Container(); + const pointer = new MockPointer(stage); + const graphics = new PIXI.Graphics(); + const mask = new PIXI.Graphics(); + const spy = sinon.spy(); + + graphics.interactive = true; + graphics.beginFill(0xFF0000); + graphics.drawRect(0, 0, 50, 50); + graphics.on('click', spy); + stage.addChild(graphics); + mask.beginFill(); + mask.drawRect(0, 0, 50, 50); + graphics.mask = mask; + + pointer.click(10, 10); + + expect(spy).to.have.been.calledOnce; + }); + + it('should not trigger interaction callback when mask doesn\'t use beginFill', function () + { + const stage = new PIXI.Container(); + const pointer = new MockPointer(stage); + const graphics = new PIXI.Graphics(); + const mask = new PIXI.Graphics(); + const spy = sinon.spy(); + + graphics.interactive = true; + graphics.beginFill(0xFF0000); + graphics.drawRect(0, 0, 50, 50); + graphics.on('click', spy); + stage.addChild(graphics); + mask.drawRect(0, 0, 50, 50); + graphics.mask = mask; + + pointer.click(10, 10); + + expect(spy).to.have.not.been.called; + }); + + it('should trigger interaction callback when mask doesn\'t use beginFill but hitArea is defined', function () + { + const stage = new PIXI.Container(); + const pointer = new MockPointer(stage); + const graphics = new PIXI.Graphics(); + const mask = new PIXI.Graphics(); + const spy = sinon.spy(); + + graphics.interactive = true; + graphics.beginFill(0xFF0000); + graphics.hitArea = new PIXI.Rectangle(0, 0, 50, 50); + graphics.drawRect(0, 0, 50, 50); + graphics.on('click', spy); + stage.addChild(graphics); + mask.drawRect(0, 0, 50, 50); + graphics.mask = mask; + + pointer.click(10, 10); + + expect(spy).to.have.been.calledOnce; + }); + + it('should trigger interaction callback when mask is a sprite', function () + { + const stage = new PIXI.Container(); + const pointer = new MockPointer(stage); + const graphics = new PIXI.Graphics(); + const mask = new PIXI.Graphics(); + const spy = sinon.spy(); + + graphics.interactive = true; + graphics.beginFill(0xFF0000); + graphics.drawRect(0, 0, 50, 50); + graphics.on('click', spy); + stage.addChild(graphics); + mask.drawRect(0, 0, 50, 50); + graphics.mask = new PIXI.Sprite(mask.generateCanvasTexture()); + + pointer.click(10, 10); + + expect(spy).to.have.been.calledOnce; + }); + }); });