PDA

View Full Version : Help with character movement



Lonesight
July 9th, 2006, 10:26 AM
Okay well im new at this whole flash thingy and ive read the tutorials on how to make Role Playing games. The thing is, now that ive got the character movment done I need a way to make so that when the character presses left the sprite changes to to the left facing sprite. the same with the right and the back facing direction. in other words i need to learn how to make the sprite walk in all directions with the sprites changing depending on the direction.

Like this character i made walks in four directions and is animated with four frames for each direction.

http://i50.photobucket.com/albums/f312/Lonesight/Legend%20of%20the%20Lone%20Hope%202/Axel.png

http://i50.photobucket.com/albums/f312/Lonesight/Legend%20of%20the%20Lone%20Hope%202/Axelwalking.gif



onClipEvent (load) {
walkSpeed = 10;
stop();
}
onClipEvent (enterFrame) {

if (Key.isDown(Key.UP)) {
play();
_y-= walkSpeed;
}
if (Key.isDown(Key.RIGHT)) {
play();
_x+= walkSpeed;
}
if (Key.isDown(Key.LEFT)) {
play();
_x-= walkSpeed;
}
if (Key.isDown(Key.DOWN)) {
play();
_y+= walkSpeed;
}

if (!Key.isDown(key.UP) & !Key.isDown(key.DOWN) & !Key.isDown(key.LEFT) & !Key.isDown(key.RIGHT)) {

stop();

}

}

SacrificialLamb
July 9th, 2006, 09:06 PM
Will to do it you make the 4 .gif’s then import them to flash. Flash will make them in to 12bitmap’s and 4 .gif file and 4 move clip’s. for some reason when I did it the last frame was superimposed on the second to last frame, to fix this I made 4 more gif’s of just the last frame found the right bitmap and re-imported it.
You then would probably want to clean up the library a bit. I put all the non move clip files in to an “images file” and that folder and the other 4 move clips in to a “char animation files” folder.
Next make a Char move clip named “char” put the 4 animation move clips in there about 10 frames apart (lave 1 empty keyframe at the start). Then make another layer named “labels” put a keyFrame where each MC starts and name it “left”,”right”, “up”, “down” and at the end I added one named “holt” on the frame on the layer with all the animation I put the bitmap that had the char facing ford with both feet on the ground. Then make a new layer named “code”. In the first frame put the code “gotoAndStop("holt");” .
Back on the mane time line (_root), make a new layer named “code” and add this code


walkSpeed = 10;
char.onEnterFrame = function() {
if (Key.isDown(Key.UP)) {
way="up"
this.gotoAndStop("up");
_y -= walkSpeed;
}
if (Key.isDown(Key.RIGHT)) {
way="right"
this.gotoAndStop("right");
_x += walkSpeed;
}
if (Key.isDown(Key.LEFT)) {
way="left"
this.gotoAndStop("left");
_x -= walkSpeed;
}
if (Key.isDown(Key.DOWN)) {
way="down"
this.gotoAndStop("down");
_y += walkSpeed;
}
if (!Key.isDown(key.UP) & !Key.isDown(key.DOWN) & !Key.isDown(key.LEFT) & !Key.isDown(key.RIGHT)) {
_root.char[way].gotoAndStop(1);
}
};

edit: the .swf was working on my computer... I swear :s
replaced the one that was not working

Lonesight
July 9th, 2006, 09:14 PM
Hey can u upload the fla file so i can see what u did i understand but if i saw it i think i would grasp it better

thanks for the info your a big help

SacrificialLamb
July 9th, 2006, 10:14 PM
the file was to big for this site (96KBs) but it works when i tack out the img's. I’ll upload them separate

note: you really don't need right and left animations you can use the same one reversed

Lonesight
July 10th, 2006, 09:34 AM
Ok i followed your instructions and my Fla file dosent work at all, maybe you can open it and help me learn what I did wrong

the file is in the link
http://www.box.net/public/te060tbt1l

SacrificialLamb
July 10th, 2006, 03:24 PM
you need to name the instance of "char" on the stage "char" there is a little box under where it says "Movie Clip" you need to change this.
also (i may have not mentioned this) you need to go into char and need to name the left right up and down instances "left","right"...
and you have not put a stationery image of char under "holt", and it’s customary to put the code on the "code" layer but this is of lest important

Lonesight
July 10th, 2006, 05:17 PM
I did what you said and i can see the character move and what not but how do i make it so that if i dont press a directional key it stands facing the direction like if it was walking up and stoped that directional facing would be in that direction

SacrificialLamb
July 10th, 2006, 05:28 PM
this part should do that


you need to go into char and need to name the left right up and down instances "left","right"...
and you have not put a stationery image of char under "holt"
i don't have the file with me now, but if you still can't work it out i'll sign up to some where where i can uplode a file of that size. or you could pm me an E-mail addres.

andychew
September 28th, 2006, 05:58 AM
Will to do it you make the 4 .gif’s then import them to flash. Flash will make them in to 12bitmap’s and 4 .gif file and 4 move clip’s. for some reason when I did it the last frame was superimposed on the second to last frame, to fix this I made 4 more gif’s of just the last frame found the right bitmap and re-imported it.
You then would probably want to clean up the library a bit. I put all the non move clip files in to an “images file” and that folder and the other 4 move clips in to a “char animation files” folder.
Next make a Char move clip named “char” put the 4 animation move clips in there about 10 frames apart (lave 1 empty keyframe at the start). Then make another layer named “labels” put a keyFrame where each MC starts and name it “left”,”right”, “up”, “down” and at the end I added one named “holt” on the frame on the layer with all the animation I put the bitmap that had the char facing ford with both feet on the ground. Then make a new layer named “code”. In the first frame put the code “gotoAndStop("holt");” .
Back on the mane time line (_root), make a new layer named “code” and add this code

ActionScript Code:

</p>
<p> walkSpeed = 10;</p>
<p>char.onEnterFrame = function() {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if (Key.isDown(Key.UP)) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;way="up"</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.gotoAndStop("up");</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_y -= walkSpeed;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if (Key.isDown(Key.RIGHT)) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;way="right"</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.gotoAndStop("right");</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_x += walkSpeed;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if (Key.isDown(Key.LEFT)) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;way="left"</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.gotoAndStop("left");</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_x -= walkSpeed;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if (Key.isDown(Key.DOWN)) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;way="down"</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.gotoAndStop("down");</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_y += walkSpeed;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if (!Key.isDown(key.UP) & !Key.isDown(key.DOWN) & !Key.isDown(key.LEFT) & !Key.isDown(key.RIGHT)) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_root.char[way].gotoAndStop(1);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>};





edit: the .swf was working on my computer... I swear :s
replaced the one that was not working

WHen i press Left,RIght,UP,Down twice, the animate does not work already!!!but it still can move. how to fixed that?