2017-10-05 114 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

問題在於鼠標似乎無法與相鄰和下方的圖層進行交互。 –

相關問題