PDA

View Full Version : [AS2] Snow Tutorial


Hellsbells87
04-04-2009, 09:39 PM
Hi,

I have been following this tutorial for falling snow:

http://www.kirupa.com/developer/actionscript/snow.htm

You can download the flash file here:

http://www.kirupa.com/developer/actionscript/code/snow_tutorial.fla

The main code is:


onClipEvent (load) {
// this random number sets a random x location for the new snowFlake and sets y location at -10
this._x = random(300);
this._y = -10;
// this sets the y and x points which the snowFlake will rotate around.
yCenterSpin = 0;
xCenterSpin = this._x+100;
// scaleIt set variables
yscaleIt = 1;
xscaleIt = 1;
this._yscale=100;
this._xscale=100;
}
onClipEvent (enterFrame) {
// if the _yscale of the movie clip is less than -100 reverse the scaling.
if (this._yscale<=-100) {
yscaleIt *= -1;
// if the _yscale of the movie clip is greater than 100 reverse the scaling.
} else if (this._yscale>=100) {
yscaleIt *= -1;
}
// if the _xscale of the movie clip is less than -100 reverse the scaling.
if (this._xscale<=-100) {
xscaleIt *= -1;
// if the _xscale of the movie clip is greater than 100 reverse the scaling.
} else if (this._xscale>=100) {
xscaleIt *= -1;
}
// random modifier to reverse it again, occationaly, not always
if (random(10)<=1) {
yscaleIt *= -1;
}
if (random(10)<=1) {
xscaleIt *= -1;
}
//add a little rotation into the mix
if (yscaleIt>0){
this._rotation+=5;
}
if (yscaleIt<0){
this._rotation-=5;
}
// scale the snowFlake
this._yscale -= yscaleIt*5;
this._xscale -= xscaleIt*5;
// move the yCenterSpin point down by a measure of 0 to 10
yCenterSpin += 3;
// change, or keep the same, the velocity
this._y += yVelocity;
this._x += xVelocity;
if (this._y>=yCenterSpin) {
yVelocity -= 1;
} else if (this._y<=yCenterSpin) {
yVelocity += 1;
}
if (this._x>=xCenterSpin) {
xVelocity -= 1;
} else if (this._x<=xCenterSpin) {
xVelocity += 1;
diff = yCenterSpin-this._y;
yVelocity += diff/200;
diff = xCenterSpin-this._x;
zVelocity += diff/200;
}
//get rid of extra clips
if (this._y>=800) {
this.removeMovieClip();
}
}


However, I want the snow to fall lower down, I changed:

this._y = -10;

to somehthing like 500 so it's about half way down the canvas but then the snow starts to go upwards and stuff! I want it to do exactly the same but just start in the middle of the canvas! Am I being stupid and need to change other numbers as well in the code??

Any help appreciated!! I am a bit cluelses though with AS so you may need to go slow lol.

Thanks!

Helen

tinkutr
04-21-2009, 02:17 PM
not opening. is it Cs4 version fla???

ASWC
04-21-2009, 02:24 PM
that's AS2 code.

Stroke
04-21-2009, 05:27 PM
not opening. is it Cs4 version fla???

Nope! It opens fine on CS3.

kkbbcute
04-22-2009, 05:33 AM
@Stroke: He may be using Flash 8.

Stroke
04-22-2009, 05:44 AM
@Stroke: He may be using Flash 8.

He would of then asked if it was CS3 format.fla... :p