[英]hitTestPoint with 'shapeFlag=true' doesn't work in AS3
[英]hitTestPoint() shapeFlag not working on movieClip containing loaded swf
我有一個.swf文件,其中包含一個從URL加載的圓圈,並放入movieClip中並將其添加到舞台中。
我希望能夠檢測到用戶何時將光標放在圓圈上。 從某種意義上講,我希望它是准確的,它不只是使用圓的邊界框,而是使用實際的圓本身來檢測碰撞。 這是我當前代碼的一部分:
//
var myCircle:MyCircle = new MyCircle(swf);
myCircle.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
myContainer.addChild(myCircle);
//
private function onMouseMove(event:MouseEvent):void
{
var glowFilter:GlowFilter = new GlowFilter();
glowFilter.color = 0xffffff;
if (event.currentTarget is MyCircle) {
var object:MyCircle = event.currentTarget as MyCircle;
if(object.hitTestPoint(event.stageX, event.stageY, true))
event.currentTarget.filters = [glowFilter];
else
event.currentTarget.filters = [];
}
}
我被認為是hitTestPoint()
方法的shapeFlag
參數可以做到這一點,但是將其設置為true或false都沒有區別。 任何想法為什么會這樣?
我在較早的時候寫了一篇很短的博客文章,所以我以后會用到它。
似乎您正在查看stageX,該AFAIK是對象的全局x坐標。
http://messer1024.blogspot.se/2012/06/proper-hittest-in-as3.html
簡短帖子的簡短版本:
經過在AS3中處理擊鍵測試的許多丑陋嘗試之后,我終於設法解決了我所尋找的問題。 我忘了考慮的事情是使用全局鼠標坐標。
public function hitTestMouse(hitarea:DisplayObject):Boolean {
return hitarea.hitTestPoint(hitarea.stage.mouseX, hitarea.stage.mouseY, true);
}
最后一個參數(shapeFlag)將決定是否檢查點擊測試,鼠標懸停在點擊區域內的任何實際形狀。
因此,為了使您的東西正常工作,您可能應該使它更容易一些,並添加我的函數,然后在您想對其進行測試時運行“ hitTestMouse(myCircle)”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.