Flash Actionscript + detecting collision at edges
I have two circular objects. I'm trying to detect as soon as the circles touch. The trace detects a collision when one circle reaches the center of the other but I want the collis开发者_如何学运维ion to be detected as soon as the circles touch.
My two symbols are coin_mc and mugbounds_mc.
function checkHitArea(evt:Event)
{
if (coin_mc.hitTestPoint(mugbounds_mc.x,mugbounds_mc.y, true)) {
coin_mc.x=-1;
coin_mc.y=-1;
trace("Hit Mug"); // Is triggered when coin_mc reaches center of mugbounds_mc
}
else
{
trace("Didn't Hit Mug");
}
}
Try this:
addEventListener(Event.ENTER_FRAME, checkHitArea)
function checkHitArea(e:Event)
{
a.x += 2;
if (a.hitTestPoint(b.x,b.y, false))
{
// do our in-circle check
if((a.x - b.x) * 2 + (a.y - b.y) * 2 <= (a.width/2 + b.width/2) * 2)
{
trace("hit");
}
}
else
{
trace("Didn't Hit Mug");
}
}
I renamed your movie clips to a and b.
精彩评论