Simple_Particle Practice

Vodpod videos no longer available.

var numOfParticles:uint=50;
var particles_ary:Array=[];

function updateStage(evt:Event):void {
if (particles_ary.length<numOfParticles) {
var ball:Ball = new Ball();
addChild(ball);
ball.xVelocity=Math.random()*10-5;
ball.yVelocity=Math.random()*10-5;
ball.x=stage.stageWidth/2;
ball.y=stage.stageHeight/2;
particles_ary.push(ball);
}
for (var i:uint = 0; i < particles_ary.length; i++) {
var particle:Ball = particles_ary[i];
particles_ary[i].update();
if(particle.x > stage.stageWidth + particle.width / 2 || particle.x < -particle.width / 2 || particle.y > stage.stageHeight + particle.height/2 || particle.y < -particle.height/2) {
particle.xVelocity = Math.random() * 10 – 5;
particle.yVelocity = Math.random() * 10 – 5;
particle.x = mouseX;
particle.y = mouseY;
}
}
}

addEventListener(Event.ENTER_FRAME, updateStage);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s