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.xVel = Math.random() *11 - 6;
p.yVel = -20;
p.yAcc = 1;
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{
for (var j=0; j<10; j++){
myArray[j].x += myArray[j].xVel;
myArray[j].y += myArray[j].yVel;
myArray[j].yVel += myArray[j].yAcc;
}
}
Hi,
I have the above code which creates a simple particle system.
I created this with the help of people form this forum and I understand
everything except one thing…
myArray[j].x += myArray[j].xVel;
myArray[j].y += myArray[j].yVel;
myArray[j].yVel += myArray[j].yAcc;
why ?
myArray[j].x += myArray[j].xVel;
myArray[j].y += myArray[j].yVel;
and not just…?
myArray[j].x += xVel;
myArray[j].y += yVel;
Also how does myArray know what to do with the property yVel, if all
it is is a number that was assigned to “p”? Couldn’t this be just
yVel += yAcc;
why assign it as a property to each
“p” in the array?
Can someone help me understand this concept? I believe this is part of OOP where properties are assigned to objects but I just don’t see it here.
Thanks a lot!