hitTest 或 hitTestObject 来检测与 AS3 中多个对象的碰撞?

hitTest or hitTestObject to detect a collision with multiple objects in AS3?

我正在开发一款小游戏,我想检测玩家是否与舞台上的其中一个盒子发生碰撞。 hitTesthitTestObject 最好的方法是什么? 我的代码:

var hitTestClips:Array = [smallbox, mediumbox, bigbox] //more to come

    var fps = 60;
    var moveTimer:Timer = new Timer(1000/fps);

    moveTimer.addEventListener(TimerEvent.TIMER, onMoveTimer);
    moveTimer.start();

    function onMoveTimer(e:TimerEvent){
    player.x += Math.round(1)

    for(var player:MovieClip in hitTestClips)
    {
      if(player.hitTest(this.x, this.y, true))
      {
        trace("HIT");
      }
    }

    }

您可以遍历敌人对象并使用 hitTestObject 查看是否发生了碰撞。

var hasCollision:Boolean = player.hitTestObject( enemy );

此页面介绍了此方法和其他各种方法:AS3 Collision Detection