【问题标题】:hitTest or hitTestObject to detect a collision with multiple objects in AS3?hitTest 或 hitTestObject 在 AS3 中检测与多个对象的碰撞?
【发布时间】:2015-01-17 14:16:33
【问题描述】:

我正在开发一个小型游戏,我想检测玩家是否与放置在舞台上的一个盒子发生碰撞。 最好的方法是什么,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");
      }
    }

    }

【问题讨论】:

    标签: actionscript-3 hittest


    【解决方案1】:

    您可以遍历敌人的物体并使用 hitTestObject 来查看是否发生了碰撞。

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

    此页面描述了此方法和其他各种方法:AS3 Collision Detection

    【讨论】:

    • 谢谢!快速提问:hitTestPoint 仅用于用户鼠标的命中测试,对吧?
    • 它可以用于任何具有 x,y 坐标的东西。使用点是处理这两个数字的一​​种非常方便的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多