dimanche 9 avril 2017

Flash execution looping issue(Should be easy to you guys)

Okay so I am just a basic programmer in Flash and I can't solve this.

How do I make an ActionScript execute only once?

This is my code:

stage.addEventListener(Event.ENTER_FRAME,loop);
function loop (event:Event):void
{
        if(runner.hitTestObject(healthbottle1)){
        healthno.text=health;
        health=health+1;
        healthbottle1.visible=false;
    }
    if(runner.hitTestObject(killer)){
        healthno.text=health;
        health=health-1;
    }
    if(runner.hitTestObject(killer2)){
        healthno.text=health;
        health=health-1;
    }
    if(runner.hitTestObject(killer3)){
        healthno.text=health;
        health=health-1;
    }
}

RESULT:
When the runner hits the killer... it'll go fast and repeatedly decreases the health number...

THE SAME WITH THE HEALTH BOTTLE BUT INSTEAD GOES RAPIDLY UP HEALTH EVEN WHEN IT DISAPPEARS.

Aucun commentaire:

Enregistrer un commentaire