A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: flying leaf, random,horizontal???

Threaded View

  1. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    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;
    }


    Last edited by jbum; 10-13-2004 at 02:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center