![](/img/trans.png)
[英]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.