ForumsProgramming ForumNeed Urgent Help!

3 2907
Njaard
offline
Njaard
133 posts
90

Well.. I'm working on a flash game (platformer), and I've made a walking animation. No matter how hard I try it simply walks all the time (or is not walking at all).. can anyone help me limit the walking to when you push the directional keys?

  • 3 Replies
ZeroUltimax
offline
ZeroUltimax
10 posts
60

i have a simple "code" for this at home. right now, im at school, but ill try and describe it as much as possible.
in your movie clip, make a frame on your charracter simply standing still(frame 1), one of your character going left (frame 2) and one of your character going right (frame 3)

now, back to the main stage, select your character movie clip and insert the code below into the action pannel.
*Reminder : this code might be incorrect, i will post a good version in few hours. i am only posting this because its URGENT!

//start script here
onClipEvent (load) {
walkSpeed = 5;
//defines walking speed
}

onClipEvent (enterFrame) {
//so it starts every frame
if (Key.isDown(key.RIGHT)) {
_x+= walkSpeed;
//moves clip right
gotoandstop(3)
//animation on character going right
}else{
//the else is very important, it makes it possible that if neither key is pressed, character plays animation 1
if (Key.isDown(key.LEFT)) {
_x-= walkSpeed;
gotoandstop(2)
}else{
gotoandstop(1)
}
}
}

warning, brackets might be missing

ThexDancingxMuffin
offline
ThexDancingxMuffin
63 posts
50

I don't seem to have that problem. I'm using this code:


onClipEvent (load) {
moveSpeed = 15;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
}
if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
if (Key.isDown(Key.DOWN)) {
this._y+=moveSpeed;
}
if (Key.isDown(Key.UP)) {
this._y-=moveSpeed;
}
}

ZeroUltimax
offline
ZeroUltimax
10 posts
60

well, your code can work if you animation is isometric, and it works easely for moving up/down/left/right, but you're forgetting he's making a platformer. the use of the gotoandstop sends you to the moving animation

Showing 1-3 of 3