Hi,
I have this code where my particle randomly goes to the right or the left in which I’m not using arrays (simple particle).
var p:Particle = new Particle();
p.x = stage.stageWidth/2;
p.y = stage.stageHeight/2;
p.alpha = Math.random () * 1 + .5;
p.scaleY = scaleX = Math.random () * 2 + .5;
addChild(p);
var xVel:Number = Math.random() *11 - 6;
var yVel:Number = -20;
var yAcc:Number = 1;
addEventListener(Event.ENTER_FRAME, moveParticles);
function moveParticles (event:Event):void{
p.x += xVel;
p.y += yVel;
yVel += yAcc;
}
I would like to do the same thing with the objects witting an array ( disperse some particles to the right and some to the left), but for some reason all particles go straight up, what am I doing wrong?
var myArray:Array = new Array();
for (var i=0; i<10; i++){
var p:Particle = new Particle();
p.x = stage.stageWidth / 2;
p.y = Math.random() * 400;
p.alpha = Math.random () * 1 + .5;
p.scaleY = scaleX = Math.random () * 2 + .1;
addChild(p);
myArray.push(p);
}
addEventListener(Event.ENTER_FRAME, moveParticles);
function moveParticles (event:Event):void{
var xVel:Number = Math.random() *11 - 6;
var yVel:Number = -20;
var yAcc:Number = 1;
for (var j=0; j<10; j++){
myArray[j].x += xVel;
myArray[j].y += yVel;
yVel += yAcc;
}
}
Thanks a lot!