是否可以为两个精灵重叠调用鼠标事件?我试图使用getObjectsUnderPoint
但它似乎没有用。
class Line extends Sprite
{
int x;
int y;
int type;
var tempLine = new Shape();
bool isClicked = false;
Line(int xPos, int yPos, int type)
{
this.x = xPos;
this.y = yPos;
this.type = type;
if(type == 1)
{
graphics.beginPath();
graphics.moveTo(x, y);
graphics.lineTo(x+300, y);
graphics.closePath();
graphics.strokeColor(Color.LightGray,19);
addEventListener(MouseEvent.CLICK, react);
tempLine.graphics.beginPath();
tempLine.moveTo(x,y);
tempLine.graphics.lineTo(x+300,y);
tempLine.graphics.closePath();
}
else if(type == 2)
{
graphics.beginPath();
graphics.moveTo(x, y);
graphics.lineTo(x, y+300);
graphics.closePath();
graphics.strokeColor(Color.LightGray,19);
addEventListener(MouseEvent.CLICK, react);
tempLine.graphics.beginPath();
tempLine.moveTo(x,y);
tempLine.graphics.lineTo(x,y+300);
tempLine.graphics.closePath();
}
addChild(tempLine);
}
react(MouseEvent event)
{
Point tempPoint = new Point(event.localX, event.localY);
graphics.strokeColor(Color.Black,19);
isClicked = true;
var subShape = getObjectsUnderPoint(tempPoint);
for(Shape i in subShape)
{
i.parent.userData.isClicked = true;
}
}
}
我有两个Line
个对象重叠,当点击一个对象时,我希望两个对象的布尔值为true
。我已经读过getObjectsUnderPoint
没有返回Sprite
,这可能是问题吗?
答案 0 :(得分:1)
MouseEvents仅被分派到扩展InteractiveObject类的最顶层显示对象(对于所有DisplayObjectContainers和Sprite都是如此)。因此,只有一个显示对象可以接收MouseEvent.CLICK事件。你是对的,getObjectsUnderPoint只返回DisplayObjectContainers的子节点,但GitHub存储库(https://github.com/bp74/StageXL/issues/209)上存在一个未解决的问题。 StageXL的下一个版本之一(大于版本0.13)可能会改变此行为。