我正在运行 HitTestPoint 来检测我的两个 mc 何时发生碰撞,但我不希望它们能够直接通过对方。有人建议我在发生碰撞时找到移动物体的 x,y 坐标,然后在每次发生碰撞时将该 mc 的坐标更新为此 x,y。我一直在谷歌搜索,但结果是空的。下面是我的代码和我尝试过的
private function __checkHit($evt:Event):void {
if (this.coin_mc.hitTestObject(target)) {
if (!hitting) {
coinSnd.play();
count++;
total_count.text = String("$" + count);
hitting = !hitting;
}
} else {
hitting = false;
}
if (mug_bounds.hitTestPoint(coin_mc.x,coin_mc.y, false))
{
// do our in-circle check
if((mug_bounds.x - coin_mc.x) * 2 + (mug_bounds.y - coin_mc.y) * 2 <= (mug_bounds.width/2 + coin_mc.width/2) * 2)
{
**var coinX:Number = coin_mc.x;
var coinY:Number = coin_mc.y;
trace(coin_mc.x);
trace(coin_mc.y);
coin_mc.x = coinX;
coin_mc.y=coinY;**
}
}
else
{
trace("Didn't Hit Mug");
}
}
}