2017-10-05 63 views
-1

好的问题是,我只是想让一个球体在它接触我的十字准线时才消失,问题是无论十字准线是否触及它,球体都会消失。as3 hittestobject会在没有运行参数的情况下激活

我的符号是:

十字线与十字线的一个实例在舞台上

目标与targetBlue的实例在舞台上

Mouse.hide(); 
crossHair.startDrag(true); 



stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown); 

function _onStageMouseDown(e:MouseEvent):void 
{ 
if (crossHair.hitTestObject(targetBlue), true) 
{ 
    targetBlue.visible = false; 
    trace("the mouse is in the target"); 
} else if (crossHair.hitTestObject(targetBlue), false){ 
    trace("the mouse is not in the target"); 
} 
} 

回答

0

你的if语句是有点怪异。 尝试这样的:

if (crossHair.hitTestObject(targetBlue) == true) { 
    targetBlue.visible = false; 
    trace("the mouse is in the target"); 
} else { 
    trace("the mouse is not in the target"); 
} 

顺便说一句,因为你很可能使某种射击游戏,我建议你检查出hitTestPoint()功能,这将是这更适合。

+0

在adobe中只有一个代码片段,我设法使用它。但是我想出了问题。我将鼠标事件从舞台更改为符号 –

+0

问题在于鼠标似乎无法与相邻和下方的图层进行交互。 –

相关问题