PDA

View Full Version : Falling snow modification



tom76
March 19th, 2003, 03:27 AM
I'm using Flash MX and am following the falling snow tutorial in the actionscript section. What I'd like is for the snow to move from right to left, but still with the random y position.

This code gives me snow (particle) moving right, left, and right again but most ends up along the top (y value of 0).

Any thoughts?

onClipEvent (load) {
//specifies the size of the movie stage
movieWidth = 131;
movieHeight = 100;

//variables that will modify the moving particle
i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;

//giving each particle unique characteristics
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 75+Math.random()*100;
this._x = -10+Math.random()*movieWidth;
this._y = -10+Math.random()*movieHeight;
}
onClipEvent (enterFrame) {
//putting it all together
rad += (k/180)*Math.PI;
this._x -= Math.cos(rad);
// this._y += i;
if (this._y>=movieHeight) {
this._y = -5;
}
if ((this._x>=movieWidth) || (this._x<=0)) {
this._x = -10+Math.random()*movieWidth;
this._y = -5;
}
}

tom76
March 19th, 2003, 05:53 AM
I've played around and got the following, but still it is not quite right.

onClipEvent (load) {
//specifies the size of the movie stage
movieWidth = 131;
movieHeight = 100;

//variables that will modify the moving particle
i = 1+Math.random()*2;
k = -Math.PI+Math.random()*Math.PI;

//giving each particle unique characteristics
this._xscale = this._yscale=50+Math.random()*100;
this._alpha = 75+Math.random()*100;
this._x = -10+Math.random()*movieWidth;
this._y = -10+Math.random()*movieHeight;
}
onClipEvent (enterFrame) {
//putting it all together
rad += (k/180)*Math.PI;
this._x -= Math.cos(rad);
// this._y += i;
if (this._y>=movieHeight) {
delete this;
}
if ((this._x>=movieWidth) || (this._x<=0)) {
this._x = -10+Math.random()*movieWidth;
this._y = -10+Math.random()*movieHeight;
}
}

tom76
March 19th, 2003, 06:14 AM
No matter, found a good effect. I changed this line

this._x -= Math.cos(rad);

to be an integer constant. Works a treat.