如何避免PIXI.js中精灵中alpha透明区域的交互性(单击等)

时间:2016-10-19 18:29:33

标签: javascript alpha pixi.js

我加载了一个hexagon.png,由于alpha值,未填充区域是透明的。当用户点击那个我希望他只能点击非透明区域以避免当六边形对齐在一起时矩形边框上的重叠事件。是否有任何能够做到这一点的功能或属性?

1 个答案:

答案 0 :(得分:1)

You can set the hitArea of a Sprite. It can be a Rectangle, Circle, or Polygon. For a 200 x 200 hexagon Sprite you could do something like this:

var points = [50,0, 150,0, 200,100, 150,200, 50,200, 0,100];
sprite.hitArea = new PIXI.Polygon(points);

**note this seems to be broken in the latest release. It was working in PIXI v3, and up until PIXI v4.0.3.