Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multible MC's - [bouncing ball]...? 1

Status
Not open for further replies.

funkymonk

Technical User
Dec 18, 2000
588
GB
Hi all,

I want to get an effect where there are loads [not sure how many yet] sphere like objects falling and bouncing about quite randomly. The sphere's will all eventually fade out to make room for more that are dropping in. I am thinking that I will have to create each [or a few] MC's individually to get this effect. Can anyone think of another, more efficient way of doing this or am I gonna have to create the bouncing ball over and over again...? roda B-)
 
I dont know how you would do this, but I know a lot of people use a type of echo effect on flash...I dont know if it's doing the same thing you are...but if you did that (if it was like a property or something)...then you could have less balls (I dont want any less balls here...but...) BUT, you would have an illusion, and fill up some space.
 
you could create it with one mc. You would need scripting to:
> increment a variable x
> duplicate the mc with name+x to depth x
> initiate random x-position for the mc (constant y for entry to screen)

on the mc you would require on 'enterframe' scripting to determine it's random path from top to bottom, decrementaly tweening the alpha on descent (as y increases). Also when, alpha =<10, say, you would remove the mc to prevent processor crunching.

blah-blah, you get the idea.

OR. (and much easier, although you won't get a fully-random bouncing effect) You create an mc containg the bouncing tween. Then all you do is duplicate the mc over and over and randomly alter the 'rotation' and x-position of the duplicated mc on load, with an action in it's final frame to remove it from the movie.

But it's probably not what you're after really, so i'll have a go at crunching an example unless someone comes back with a 'search-engine' reply containing a solution in the meantime.

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
hi roda

If you have 'any' experience with more advanced scripting you'll know what I was talking about in my first example, but I won't spend any time on it if this will suffice.

As for the second example:


Frame 1 contains the following actions:

Code:
//The maximum number of balls to be bouncing at any one time

maxball = 10;

//Increment x by one for every loop of the movie.
//This makes sure that every duplicate of the original mc
//has a unique name, allowing us to target it for removal
//when there are too many balls on the screen.

x++;

//A random number is generated. My example movie is 500 wide
//so we use this variable to set the x-position of the 
//duplicated mc, and also to check if it needs
//its orientation altered to make sure it doesn't
//bounce off the screen straight away.

randomx = random(500);

//The movie-clip with instance name &quot;mc&quot; is duplicated
//and given a new name relative to the current value of 'x'
//and is placed at a unique depth 'x'.

mc.duplicateMovieClip(&quot;mc&quot;+x, x);

//The following IF statement checks if the duplicated mc
//will bounce off the screen straight away. If it does then
//it sets its x-scale to -100 (ie: it flips it horizontally)

if (randomx < 250) {
    setProperty (&quot;mc&quot;+x, _xscale, &quot;-100&quot;);
}

//The x-position of the duplicated mc is set to the value
//of the variable 'randomx'

setProperty (&quot;mc&quot;+x, _x, randomx);

//The following IF statement starts to remove the duplicated
//movie-clips one-by-one. The removal does not commence
//until the value of 'maxball' has been reached. In this
//example I've set the maximum number of balls on screen
//to 10, so when 11 duplicates are present the first &quot;mc1&quot;
//is removed, then &quot;mc2&quot;, etc, etc

if (x>maxball) {
    removeMovieClip (&quot;mc&quot;+(x-maxball));
}
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Hi Dave,

WOW...!!!

Cheers Dave, looked like a bit of a monster till I noticed that a lot of it was //comment tags. Anyway, my scripting skills are not very advanced so the first one went straight by me. I have downloaded the .zip you put up and taken the above script so It looks like I may be staying in tonight and having a play. Looks like you put a fair bit of work into the above post, thankyou. roda B-)
 
Hi,

This was the kind of thing I was after. I just used the same MC and draged loads of them onto the stage on diferent key frames. I used no action script apart from a stop comand at the end of the tween. Like I said, my ActionScript knowledge is still quite basic. 11k file.


roda B-)
 
ahah, a pretty picture paints a thousand words ;-) nice

If you get the time, why don't you try messing around with the 'duplicate movie-clip' and 'setproperty' actions. You could achieve the same effect with one mc and some scripting, and teach yourself something on the way towards your target.

Anyway, nice work, bye for now.

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top