The following code is modified from my shooter game which has stars that move randomly horizontally.
See the original to see the effect applied to stars.
Jim's Shooter Game
The basic idea is that you have a movieclip called 'leaves' in the library. Each frame of the movieclip contains an image (or animation) of a different leaf. You might want to animate the individual leaves to tumble.
This script moves them across the screen at different rates.
code:
kNbrLeaves = 30;
kLeafLayer = 100;
SW = Stage.width; // keep track of width and height of stage
SH = Stage.height;
moveLeaf = function()
{
this._x -= this.speed;
if (this._x < -10)
this._x = SW+10;
}
// Initial Leaf setup
for (i = 0; i < kNbrLeaves; ++i) {
mc = _root.attachMovie('leaves', 'leaf_'+i, kLeafLayer+i);
mc._x = random(SW);
mc._y = random(SH);
mc._xscale = mc._yscale = 50;
mc._alpha = 50 + random(50);
mc._rotation = random(360);
mc.speed = random(10)+1;
// select random leaf (by frame) mc.gotoAndStop(random(3)+1);
mc.onEnterFrame = moveLeaf;
}
Something else you might want to try is varying the speed in the moveLeaf function. For example:
code:
moveLeaf = function()
{
// tweak the numbers .001 and 2 for different effects,
// the first number affects rate of change,
// and the second number affects amplitude of change
this.speed += Math.sin(getTimer()*.001)*2;
this._x -= this.speed;
if (this._x < -10)
this._x = SW+10;
}




Reply With Quote