Dropping multiple objects using an array in Actionscript?

Posted by Eratosthenes on Game Development See other posts from Game Development or by Eratosthenes
Published on 2012-03-26T04:02:47Z Indexed on 2012/03/26 17:40 UTC
Read the original article Hit count: 158

Filed under:
|
|

I'm trying to get these fireBalls to drop more often, I'm not sure if I'm using Math.random correctly.

Also, for some reason I'm getting a null reference because I think the fireBalls array waits for one to leave the stage before dropping another one?

This is the relevant code:

var sun:Sun=new Sun
var fireBalls:Array=new Array()
var left:Boolean;

function onEnterFrame(event:Event){
    if (left) {
        sun.x = sun.x - 15;
    }else{
        sun.x = sun.x + 15;
    }
    if (fireBalls.length>0&&fireBalls[0].y>stage.stageHeight){ // Fireballs exit stage
        removeChild(fireBalls[0]);
        fireBalls.shift();
    }
    for (var j:int=0; j<fireBalls.length; j++){
        fireBalls[j].y=fireBalls[j].y+15;
        if (fireBalls[j].y>stage.stageHeight-fireBall.width/2){
        }
    }   
    if (Math.random()<.2){ // Fireballs shooting from Sun
        var fireBall:FireBall=new FireBall;
        fireBall.x=sun.x;
        addChild(fireBall);
        fireBalls.push(fireBall);
    }
}

© Game Development or respective owner

Related posts about flash

Related posts about animation