A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Need to randomly make a MC "hover" on the X/Y co-ords

  1. #1
    Member
    Join Date
    Jan 2001
    Posts
    54

    Need to randomly make a MC "hover" on the X/Y co-ords

    I have great scripts for dynamically growing and shrinking a MovieClip with a fair amount of elasticity, but what I need now is to have several MovieClips "hover" in place on the X/Y axis with random movements, and with the movement easing in and out.

    Am I making sense? Does anyone have a script for such movement handy?

    Thanks in advance.

  2. #2
    ____________
    Join Date
    Sep 2004
    Location
    Hells Kitchen
    Posts
    191
    code:

    onClipEvent (load) {
    speed = 1;
    delay = 10;
    moveDistance = 80;
    // Adjust above
    Xpos = _x;
    Ypos = _y;
    timer = 0;
    }
    onClipEvent (enterFrame) {
    timer = timer+speed;
    if (timer>delay) {
    Xpos = _x+Math.random()*moveDistance*-1+moveDistance/2;
    Ypos = _y+Math.random()*moveDistance*-1+moveDistance/2;
    timer = 0;
    }
    _x += (Xpos-_x)/7;
    _y += (Ypos-_y)/7;
    }



    I wrote it so you can adjust the maximum distance it moves, the delay, and the speed.

    -joe
    Last edited by FlashGod.com; 09-20-2004 at 08:36 PM.
    _

    __________________

  3. #3
    Member
    Join Date
    Jan 2001
    Posts
    54
    Very cool! It works as advertised - thank you very much.

    Do you know how this could be altered so that the "hovering" item moved from a set position, so that if it began in position (20,20) it would move randomly from there, move back to (20,20), and then another random movement and so on?

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