actionscript add object on time

Discussion in 'Programming' started by Silver89, Aug 16, 2008.

  1. #1
    Hi,

    I'm creating a flash game using actionscript however I'm unsure of how to add more enemies over time.

    It's a simple dodge game where items fall from the score and you must navigate around too avoid the items, however over time, say every 10 seconds I want another object to appear.

    How can I do this?

    Thanks.
     
    Silver89, Aug 16, 2008 IP
  2. higreg7

    higreg7 Peon

    Messages:
    469
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    myInterval = setInterval(addEnnemy,10000);

    function addEnnemy (){
    your function
    }

    If you meant that you wanted to add an extra one every 10 seconds, do something like:

    var i:Number = 1;

    myInterval = setInterval(addEnnemy,10000);

    function addEnnemy (){

    //your function using i for the number of ennemies
    //add one to the variable i every time this function is called
    i++;
    }
     
    higreg7, Aug 17, 2008 IP