Copy link to clipboard
Copied
Why I get TRUE if even circle dont tuching rectangle? Maby here is the other solution for this?
trace(circe.hitTestObject(rectangle));
FALSE | TRUE |
---|---|
![]() | ![]() |
Copy link to clipboard
Copied
Every object has a bounding frame in the shape of a rectangle. As soon as you enter into that frame you effectively hit the object, even if you cannot see it.
Go thru the following article and see if you can work thru a solution...
https://www.experts-exchange.com/articles/626/Flash-Collision-Detection-using-ActionScript-3-0.html
Copy link to clipboard
Copied
OU thank you this is good lesson about this, SImple thing I want to use this:
stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(event:Event)
{
if(rect1.hitTestPoint(mouseX,mouseY,true))
{
txt_hit.text = "HIT!";
}
else
{
txt_hit.text = "";
}
}
This is works with mouse but not with objects. I mean if mouse point is over then its true. But then I add the object always I get false.
stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(event:Event)
{
if(object1.hitTestPoint(object2, true))
{
txt_hit.text = "HIT!";
}
else
{
txt_hit.text = "";
}
}
I have 45 objects (movieclips) around rotating wheel and one point (movieclip) then wheel stops I want to see points in txt_hit.text And I want something simple to do this.
Copy link to clipboard
Copied
hitTestPoint requires two parameters (an x and y) and has an optional boolean 3rd parameter. ie, you can't use an object for the first parameter and a boolean for the 2nd.
i'm not sure what exactly you're trying to do but this will be closer:
if(object1.hitTestPoint(object2.x,object2.y, true))
and if you're trying to achieve a pixel-perfect hittest, use the bitmapdata hittest.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now