Movement

Hi, :smiley:

I am trying to make a little game however at the moment i have been trying to figure out how to make my charector when idle show movieclip 1 in its place and when the left and right arrows are being pressed show movie clip 2 and for the charector to move left or right at a speed of 5 depending on what key is being pressed.

Summary:
no keys pressed - Charector idle, movie clip 1 shown on screen
Left key pressed - charector moves left at speed of 5
Right key pressed - Charectot moves right at a speed of 5

How do i do this???

here is an example…
the char is 3 key frames, with lables idle, left and right…
just look at it, it’s pretty simple for basic movement…

I can’t seem to get my else bits right :frowning:
(yes the code below is mostly borrowed from movement-keys.fla aswell :D)

After walk right i want it to go to else “idle right” and after left “idle left”

where do i place
[AS] else {
this.gotoAndStop(“idle right”);
}[/AS]
and
[AS] else {
this.gotoAndStop(“idle left”);
}[/AS]

[AS]
onClipEvent (load) {
// declare and set speed variable
speed = 5;
}
onClipEvent (enterFrame) {
// move left, or right
if (Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT)) {
_x -= speed;
this.gotoAndPlay(“walk left”);
}
if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT)) {
_x += speed;
this.gotoAndPlay(“walk right”);
}
//
// move diagonally
if (Key.isDown(Key.LEFT) && Key.isDown(Key.UP) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.DOWN)) {
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.UP) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.DOWN)) {
}
if (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP)) {
}
if (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.UP)) {
}
//
// loop to opposite side of the masked area when the beetle travels off-screen
if (_y<0) {
_y = 60;
}
if (_y>60) {
_y = 0;
}
if (_x<0) {
_x = 300;
}
if (_x>300) {
_x = 0;
}
//
// maintain position and rotation of beetle shadow
with (_root.shadow) {
_x = this._x+3;
_y = this._y+3;
_rotation = this._rotation+90;
}
}

[/AS]

ps i know half of the code there i don’t need for what i am doing but i may find a use for it so i kept it there :slight_smile:

Thank You for the help :smiley: