Forums

ForumsProgramming Forum

Need Urgent Help!

Posted May 1, '08 at 11:09am

Njaard

Njaard

137 posts

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?

 

Posted May 1, '08 at 1:23pm

ZeroUltimax

ZeroUltimax

10 posts

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

 

Posted May 1, '08 at 8:10pm

ThexDancingxMuffin

ThexDancingxMuffin

64 posts

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;
    }
}

 

Posted May 2, '08 at 11:46am

ZeroUltimax

ZeroUltimax

10 posts

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

 
Reply to Need Urgent Help!

You must be logged in to post a reply!