Basic Movement
Left, right, down, up, and diagonal movement
On the main stage, select the MC you wish to make move
Add Actions:
onClipEvent(load){
speed=10; stop();
}
onClipEvent (enterFrame) {
_x+=Key.isDown(Key.RIGHT)*speed;
_x-=Key.isDown(Key.LEFT)*speed;
_y+=Key.isDown(Key.DOWN)*speed;
_y-=Key.isDown(Key.UP)*speed;
}
Unfortunately, this one doesn't allow for changing the orientation (eg walking)... so
Left, right, down, up movement with orientation
Create a new MC with 4 frames.
On the first frame, add your character walking right.
On the second frame, add your character walking down.
Third frame, left. Fourth frame, up.
Put the MC on the stage and add these actions:
onClipEvent(load){
speed=10; stop();
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){_x+=speed; gotoAndStop(1);}
if (Key.isDown(Key.DOWN)){_y+=speed; gotoAndStop(2);}
if (Key.isDown(Key.LEFT)){_x-=speed; gotoAndStop(3);}
if (Key.isDown(Key.UP)){_y-=speed; gotoAndStop(1);}
}
---------------------------------
If you wish to use the WASD keys, the keycodes are:
WASD -- ARROWS -- A.KEYS
- (68) ------ (39) ------ (Key.RIGHT)
- (65) ------ (37) ------ (Key.LEFT)
- (87) ------ (38) ------ (Key.UP)
- (83) ------ (40) ------ (Key.DOWN)
Use them like this:
_x+=Key.isDown(39)
or
if (Key.isDown(39)){_x+=speed;}
Other useful ones:
SPACE -------- (32)
ALT ------------ (18)
ENTER -------- (13)
BACKSPACE --- (8)
SHIFT --------- (16)
Z --------------- (90)
X --------------- (88)
C -------------- (67)