A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Random Speed

  1. #1
    Ok here's the deal.

    I have a small movieclip in which an object moves from the left of my screen to the right at a certain speed. I have this movieclip on several places on the screen, didn't use duplicate MC because I needed them to be on a specific spot. So imagine it, objects all moving at the same speed from the left to the right.

    Now, the object move from the left to the right, but currently all have the same speed. How can I create an actionscript that moves the objects from left to right at a random speed?? It's a little like the starfield, but then not with levels.

    Please help me on this one, doing it manually is a pain in the ***

    Thanks
    2Design

  2. #2
    Senior Member webgeek's Avatar
    Join Date
    Sep 2000
    Posts
    1,352
    Set the entire movie to a very fast frame rate. Have a variable called "delay" and "currentFrame" associated with the movie clip. Then randomly set the value of delay. Then do an if statement to handle the movement inside of the onFrameEvent(enterFrame):

    Code:
    if (delay == currentFrame) {
         moveClip()
         currentFrame = 1
    } else {
         currentFrame++
    }
    You could easily create an array on the main timeline that contained all the movie clip names and then have a controller clip that loops over the array and does this every frame. This should work just fine and its pretty simple to implement.

    Mike Grundvig

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