Ok so i'm working on making a platformer game for my first flash. I'm having some problems with making my character do a walking animation correctly. FLASH says there are no problems with the script and everything works except that one part.
Heres the code::
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 5;
var maxJump:Number = -18;
var touchingGround:Boolean = false;
facing = 1;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(key.RIGHT)) {
facing = 1;
this.gotoAndPlay(3);
_x += speed;
} else {
if (facing == 1) {
this.gotoAndStop(1);
} else if (facing == 2) {
this.gotoAndStop(2);
}
}
if (Key.isDown(key.LEFT)) {
facing = 2;
this.gotoAndPlay(4);
_x -= speed;
} else {
if (facing == 1) {
this.gotoAndStop(1);
} else if (facing == 2) {
this.gotoAndStop(2);
}
}
if (Key.isDown(key.UP) && touchingGround) {
grav = maxJump;
}
}