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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Multiple Objects in a Pattern 1

Status
Not open for further replies.

Kison

Programmer
May 4, 2004
14
US
Hey all,

This is a very odd question, but I can't find a good answer for it. Let us say, in this scenerio, that I want to animate an army of ten people marching accross the screen, from right to left. I know I could use a tween and movie clip, using ten different layers, but let's say I want 20. Does it make sense to use 20 layers just for that? Not really. I came up with the idea that I could make a tween within a movie clip, and re-use it. There are flaws here, as well. Using a movie clip tween doesn't give me a specific ending location of the moving person that I want to have walking accross the screen.

My question is, if I want to have 20 stick figures just walking accross a screen, what is the best way to go about this? Is there a way to do this in ActionScript? Or can movie clips have this done in an easier manner?

Thanks. :p
 
If you want the walk to look realistic the best thing to do is to create a 'walk cycle' this is the animation needed for two steps - one with the right foot, one with the left.

Then you repeat this move in a movieclip and move the clip after each step. This looks better than a tween because it doesn't glide smoothly - it looks like a traditional cartoon.

Once you have it as one movie clip it's easy to duplicate it as many times as you want.

It's easier to see it work than explain it so here's and example:


Some source which gives you the actionScript that runs it:

 
Thanks for the reply. The first link works, but the download you sent doesn't open.

You are saying that I need to make a movie clip that has one walk cycle, and just move it after each step? So let us say that one step with the right foot takes 2 frames, and one with the left foot takes 2 frames, every two frams I'll move the movie clip?

If that's the case, I should have it worked out, but you mentioned actionscript. What would I need to do with that?
 
Try downloading the file again - the last one was MX2004, this one is MX only.

The actionscript is more or less what you mentioned but the cycle is longer than you suppose - hopefully you'll be able to see what I mean in the .fla

Basically the cycle animation lasts for 18 frames, during that cycle the character moves 105 pixels to the left. Once the step is complete the cycle starts again and the actionscript moves the whole movieclip 105 pixels to the left so that the transition is seamless.

In this way you get to use one movieclip, cutting down on animation time and filesize, while still having a decent looking character instead of something that tweens smoothly from one side to the other waving its legs around and doesn't actually look connected to the ground.
 
The second link brings me to a white page with no download. And I'm using Macromedia Flash 5, if that makes any difference.

Thanks for the post again, at least I know I'm not using the best method. ;)
 
Flash 5 makes all the difference, you won't be able to use the code anyway but the principle is sound.
 
Is it possible to do in Flash 5, though?
 
Sure but I can't post a file to help you because I can only save out of MX2004 as MX not 5. Here's some code which might help:

Code:
moveCharacter = function () {
	with (character_mc) {
		if (_currentframe == _totalframes) {
			_x -= 105
			gotoAndStop(1);
		} else {
			nextFrame();
		}
	}
};

Where 105 is the step length of the animation and character_mc is the movieclip you're animating. In Flash 5 you would trigger this function from:

Code:
onClipEvent(enterFrame){
_root.moveCharacter();
}

...sitting on another movieclip somewhere in your movie.
 
I would put the first code you posted on the movie clip I am using, and what kind of movie clip would I put the second on? Just a random movie clip I would never use?
 
You could put the enterFrame clipEvent on the actual character clip if you want and change:

Code:
with (character_mc) {

to

Code:
with (this){

so it would read:

Code:
onClipEvent(enterFrame){
 with (this) {
        if (_currentframe == _totalframes) {
            _x -= 105
            gotoAndStop(1);
        } else {
            nextFrame();
        }
    }
};

But I suggest creating a specific 'control' clip - an empty movieclip which is only on the stage in order to act as a holder for clip events. This way if you are going to create multiple characters then you can control them all from the same clip rather than have each one generating its own clipEvents which will eat your CPU.
 
Ok, what I did was I made one movie clip with nothing in it. With this blank movie clip, I put the first actionscript you posted in to it. But I put it in the first frame of the script. I'm not sure if I am suppose to put it there or rightclick the movie clip and hit actions and put it in there.

I made a movie clip with 2 pictures, one of the guy standing and one of his legs in movement. I right clicked the actionscript and put the script in there.

Now when I test the movie, it shows the guy just walking in place and I get the following error:

Symbol=WalkMan, Layer=Layer 1, Frame=1: Line 1: Clip events are permitted only for movie clip instances
onClipEvent(enterFrame){


I guess maybe I put it in the wrong place. :p
 
ClipEvent code doesn't go on frames, that's why you're getting the error - it actually attaches to the clip itself.
Select the clip on the stage and paste the code into the actions window.
 
I moved them from the frame to the movieclips themselves, and receive the same error. Does it matter if it is in normal mode or expert mode, the scripts? I set them to expert mode.
 
Ahh, man, you didn't have to go through all of that. :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top