ForumsProgramming ForumWalking people?

6 3424
gnicol116
offline
gnicol116
15 posts
Nomad

How do you make it so when you press a button, it makes them walk with a motion, not just floating forward?

  • 6 Replies
Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

You mean an animation?

Drace
offline
Drace
3,880 posts
Nomad

Depends...
What program are you using?

Gametesta
offline
Gametesta
1,707 posts
Nomad

walking people. *thinks to himself* what a novel idea.

GodGilliam
offline
GodGilliam
60 posts
Nomad

Obviously you need different frames so you can make the first frame go over to the one...

gnicol116
offline
gnicol116
15 posts
Nomad

I mean like in games in flash. I know how to make a an animation. I mean like you press a button and the guy walks that way. I was thinking it would be like some ianimating in a movie clip? By the way, I use CS3.

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Well, when you want to make a standing character, you just place him right there, right? Draw a stick figure standing and all is fine

If you want one that is walking, you make a walking one and he walks, however, if you have the standing and walking frames together, let's say that he has 4 animation frames walking and one standing, that would mean he would show the stand everytime he looped trough it, right?

The same would happen if we had the walking animation together with standing, but this is easier for us to code on to, so let's do it like this.

Create 1 frame for standing, transform it into a Symbol, insert a Keyframe on frame 2, make the first frame for walking, then transform it into a different symbol (you knew you could have symbols inside symbols, right?), then double click this new symbol, which should now show a new timeline, each symbol has its own timeline, then create your animation in there, and when you're finished, get back to your scene.

So you now have a character with two frames, frame 1 for standing and frame 2 where another symbol shows him walking. If you test your movie now, he will just flash between frame 1 and 2, so the first thing we'll do is to hard code a stop

character.gotoAndStop(1);


Pretty easy huh? To actually move it however will need a main loop to keep moving the character while the key is pressed, I use this.onEnterFrame

Here's my usual code for walking

this.onEnterFrame = function()
{
if (Key.isDown(39))
{
character._x = character._x + 5
character.gotoAndStop(2);
}
}


Of course, this is walking right, 39 is the value for the Right Arrow key, 37 for Left Arrow, and I put +5 on the X axis, when left will actually subtract, -5

This will keep your character at frame 2, where the other symbol will be walking. You see, unless we name that symbol's instance and tell it specifically to stop, it won't, so it's a lot easier than put all the frames on a single timeline and hard code loops

You'll also need to put a code for standing. I just place an extra variable at the walking code, like "walkingright = true;" and complement it with an else, so that it's turned false when the player is not pressing anything, so I can check if both right and left are not being used to make the character stand

Another piece of code I find very useful is _xscale, because it works with percentage, so I can flip the whole animation depending on the side he's walking to by just putting -100

this.onEnterFrame = function()
{
if (Key.isDown(39))
{
character._x = character._x + 5
character.gotoAndStop(2);
character._xscale = 100;
walkingright = true;
}
else
{
walkingright = false;
}

if (Key.isDown(37))
{
character._x = character._x + 5
character.gotoAndStop(2);
character._xscale = -100;
walking left = true;
}
else
{
walkingleft = false;
}

if(walkingright == false and walkingleft == false)
{
character.gotoAndStop(1);
}
}


I'm not sure of how much you know, so if you need more explanation on any part of this, just ask
Showing 1-6 of 6