Create nice background effects with Flash Random Movement

This is a Flash effect you can use for a background effect or for a shoot'em up wave (hint! hint!)

I received this script from Ashker (the creator of Olympclicks)

« Hello Emanuele. Today I tried to make an object move in a circular motion in Flash, and i succeeded. I also discovered that i could make other random motions by changing a few variables.

Thought of some ideas it could be used for : background animations, creating new level designs, creatin paths for Enemies. »

That's right!

With this simple script:

ACTIONSCRIPT:
  1. attachMovie("ball", "ball", 1)
  2. ball._x = 250
  3. ball._y = 200
  4. timey = 0
  5. fps = 3
  6. xvel = 0
  7. yvel = 3
  8. xcha = .1
  9. ycha = .1
  10. i = 0
  11.  
  12. onEnterFrame = function(){
  13.     timey ++
  14.     if(timey == fps){
  15.         dave = _root.attachMovie("blob","blob" + i, _root.getNextHighestDepth())
  16.         dave._x = ball._x
  17.         dave._y = ball._y
  18.         timey = 0
  19.         i++
  20.     }
  21. }
  22.  
  23. ball.onEnterFrame = function(){
  24.     this._x -= xvel
  25.     this._y -= yvel
  26.     xvel += xcha
  27.     yvel -= ycha
  28.     if(xvel>= 3 || xvel <= -3){
  29.         xcha = -xcha
  30.     }
  31.     if(yvel>= 3 || yvel <= -3){
  32.         ycha = -ycha
  33.     }
  34.     if(this._x> 500){
  35.         this._x = 0
  36.     }
  37.     if(this._x <0){
  38.         this._x = 500
  39.     }
  40.     if(this._y> 400){
  41.         this._y = 0
  42.     }
  43.     if(this._y <0){
  44.         this._y = 400
  45.     }
  46. }

playing with xvel, yvel, xcha and ycha you can achieve a wide range of effects.

Ashker invites you all to play with these variables and eventually publish here the most interesting results.

Here are some random effect you can make:

Download the source code and share interesting values, and I'll show you how to use them in a shoot'em up.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 3.86 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.
» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

4 Responses to “Create nice background effects with Flash Random Movement”

  1. Harmen on August 21st, 2008 3:16 pm

    Nice to see it, but:
    The longer you play it, the slower it goes…

  2. Harmen on August 21st, 2008 3:17 pm

    Sorry, mistake ^^ It’s not slowing down…

  3. Matt on August 22nd, 2008 7:40 pm

    I accidentily left this running for awhile and it slowed down completely and ended up freezing internet explorer when i tryed to close it.

    It’s probably because the balls are created but not deleted.

  4. Eric on April 4th, 2009 3:38 pm

    nope Matt, it’s because you use IE. :)

Leave a Reply




Posts