1

I am making a game in AS3, and I want to have a "health bar". When one of my "alien" objects hits the Earth, I would like my health to go down. I just do not know how to make the stage register that an object gone offscreen, or "hit the ground". Any help would be great!

4

1 回答 1

1
var aliens = [new Alien(), new Alien(), new Alien()];
var health = 10;

// Check position of aliens on each frame
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

function enterFrameHandler(event:Event):void
{
    for (var i:int = 0; i < aliens.length; i ++)
    {
        // If the alien's y position is equal to or greater than
        // the stage height, he's hit the deck
        if (aliens[i].y <= this.stage.stageHeight) 
        {
            health --;
        }
    }
}
于 2013-04-17T23:41:34.890 回答