[英]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 collision to be detected as soon as the circles touch.
当一个圆到达另一个圆的中心时,轨迹将检测到碰撞,但是我希望在圆接触时立即检测到碰撞。
My two symbols are coin_mc and mugbounds_mc. 我的两个符号是coin_mc和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. 我将您的影片剪辑重命名为a和b。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.