0

So, I'm trying to do this sort of thing where, if Cosmo.hitTestObject, Asteroid 5 should be removed, however I want it immediately added back at a different position, so the hit test isn't triggered automatically. How would I go about doing this?

var nCount1:Number = 0;
timer_Text1.text = nCount1.toString();
addEventListener(Event.ENTER_FRAME,massCollect);

function massCollect(e:Event) {
    if (Cosmo.hitTestObject(Asteroid5)) {
        removeChild(Asteroid5);
        nCount1++;
        timer_Text1.text = nCount1.toString();
    }
    if (nCount1 == 5) {
        gotoAndStop(351, "Scene 1");
        removeEventListener(Event.ENTER_FRAME,massCollect);
    }
}
duTr
  • 714
  • 5
  • 21
user2072135
  • 59
  • 1
  • 12

1 Answers1

0

I would go with something like this:

var nCount1:Number = 0;
timer_Text1.text = nCount1.toString();
addEventListener(Event.ENTER_FRAME, massCollect);

function massCollect(e:Event) {
    if (Cosmo.hitTestObject(Asteroid5)) {
        while (Cosmo.hitTestObject(Asteroid5) {
            Asteroid5.x = Math.floor(MAX_WIDTH * Math.random());
            Asteroid5.y = Math.floor(MAX_HEIGHT * Math.random());
        }
        removeChild(Asteroid5);
        nCount1++;
        timer_Text1.text = nCount1.toString();
    }
    if (nCount1 == 5) {
        gotoAndStop(351, "Scene 1");
        removeEventListener(Event.ENTER_FRAME, massCollect);
    }
}
duTr
  • 714
  • 5
  • 21