使用hitTestObject我可以檢查是否一個對象被hiting另一個,但如果我有10個MovieClip對象,我想檢查是否有任何對象hiting任何對象:如何在許多對象
package {
import flash.display.MovieClip;
import flashx.textLayout.events.DamageEvent;
import fl.motion.Animator;
import flash.geom.Point;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.geom.ColorTransform;
public class Test extends MovieClip {
private var arrows:Array;
private var timer:Timer;
public function Test() {
init();
}
private function init():void {
timer = new Timer(1000, 6);
timer.addEventListener(TimerEvent.TIMER, timerEvent);
arrows = new Array();
timer.start();
}
private function timerEvent(e:TimerEvent):void{
var arrow:Arrow = new Arrow();
arrow.x = 5;
arrow.y = Math.random() * 200 + 10;
addChild(arrow);
arrow.addEventListener(Event.ENTER_FRAME, onEnterFrame);
arrows.push(arrow);
//trace(555);
}
private function onEnterFrame(e:Event):void{
e.target.x += 4;
if(e.target.x > 400)
{
e.target.transform.colorTransform = new ColorTransform(0, 0, 1, 1, 0, 0, 1, 1);
e.target.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
e.target.addEventListener(Event.ENTER_FRAME, goBack);
}
}
private function goBack(e:Event):void {
e.target.x -= 4;
if(e.target.x < 50)
{
e.target.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 1, 1);
e.target.removeEventListener(Event.ENTER_FRAME, goBack);
e.target.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
}
}
如何我可以檢查是否有任何箭頭觸及其他箭頭對象?,無所謂對象,我需要類似hitTestGlobal
我認爲我需要使用for循環來檢查所有現有的對象嗎?但會降低應用程序的性能? – 2012-08-08 08:44:38