则hitTest或hitTestObject检测与AS3多个物体的碰撞? [英] hitTest or hitTestObject to detect a collision with multiple objects in AS3?

查看:259
本文介绍了则hitTest或hitTestObject检测与AS3多个物体的碰撞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个小游戏,我想,以检测球员相撞的被放置在舞台上的一个箱子。 什么是做到这一点的最好方法,则hitTest hitTestObject ? 我的code:

  VAR hitTestClips:数组= [在smallBox,mediumbox,bigbox] //更多的惊喜

    VAR FPS = 60;
    VAR moveTimer:定时器=新的定时器(1000 / fps)的;

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

    功能onMoveTimer(E:TimerEvent){
    player.x + = Math.round(1)

    对于(VAR球员:影片剪辑中hitTestClips)
    {
      如果(player.hitTest(this.x,this.y,真))
      {
        跟踪(打);
      }
    }

    }
 

解决方案

您可以通过敌人的对象回路,并使用hitTestObject,看是否发生了碰撞。

  VAR hasCollision:布尔= player.hitTestObject(敌人);
 

本页面描述了这等各种方式:<一href="http://www.tutorialized.com/tutorial/HitTest-AS3-for-collision-detection-Flash-Actionscript-3/68594"相对=nofollow> AS3碰撞检测

I'm working on a small game and I would like to detect if the player collided with one of the boxes that are placed on the stage. What is the best method to do this, hitTest or hitTestObject? My code:

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");
      }
    }

    }

解决方案

You can loop through the enemy objects and use hitTestObject to see if a collision occurred.

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

This page describes this and various other methods: AS3 Collision Detection

这篇关于则hitTest或hitTestObject检测与AS3多个物体的碰撞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆