阻止createjs鼠标穿透的方法
感谢createjs交流群的maksim大神给的方法,方法很简单就是在掩盖对象上加一个空的侦听事件,比如这样:
var shape2 = new createjs.Shape(); shape2.graphics.beginFill("#00ff00"); shape2.graphics.drawRect(0,0,100,100); shape2.graphics.endFill(); stage.addChild(shape2); shape2.x = 300; shape2.y = 100; shape2.addEventListener("click",function (){ console.log("shape2"); }) var maskShape2 = new createjs.Shape(); maskShape2.graphics.beginFill("#000000"); maskShape2.graphics.drawRect(0,0,100,100); maskShape2.graphics.endFill(); stage.addChild(maskShape2); maskShape2.alpha = 0.5; maskShape2.x = 330; maskShape2.y = 100; maskShape2.addEventListener("click",function (){});//空的鼠标侦听 可以阻止shape2被侦听
测试地址:http://www.ajexoop.com/test/clickMask/index.html
可以看到demo上shape1可以被穿透侦听,但是shape2不会。
发表评论