PDA

View Full Version : animated movement



slyerguy
September 7th, 2006, 07:36 PM
im making this game and im trying to make it that when you press the down key the character will move down and will animate it walking down and as soon as the key is released the character will stop animating and stop moving. I have the main movieclip with this code (all im working on now is the downwards movement)

onClipEvent(load){
speed = 5;
}
onClipEvent(enterFrame){
if(Key.isDown(Key.DOWN)){
this._y += speed;
this.gotoAndStop(1);
}else if(Key.isDown(Key.UP)){
this._y -= speed;
this.gotoAndStop(2);
}else if(Key.isDown(Key.RIGHT)){
this._x += speed;
this.gotoAndStop(4);
}else if(Key.isDown(Key.LEFT)){
this._x -= speed;
this.gotoAndStop(3);
}
}

and on frame 1 of the movieclip is another movieclip with this code (this movieclip is the animating one. I put this code on the movieclip so when it checks if the down key is not being pressed, it will go to frame 1 of this movieclip and stop. This is to make the character to stop facing the direction it was just moving)

onClipEvent (enterFrame) {
if (!Key.isDown(Key.DOWN)) {
this.gotoAndStop(1);
}
}

What is happening is the walking down animation isnt playing when i have the down key pressed.

DangerousDan
September 7th, 2006, 07:41 PM
Whether it it up or down isn't it playing the same animation?
ActionScript Code:

if(Key.isDown(Key.DOWN)){
this._y += speed;
this.gotoAndStop(1);
}




same as...
ActionScript Code:

if (!Key.isDown(Key.DOWN)) {
this.gotoAndStop(1);
}


So whether the key is pressed or not it plays frame 1...

slyerguy
September 7th, 2006, 07:59 PM
no the code

if(Key.isDown(Key.DOWN)){
this._y += speed;
this.gotoAndStop(1);
}

is on the main movieclip. This makes it move down and go to the first frame of this movieclip which holds the movieclip with the downwards movement animation.

the code

if (!Key.isDown(Key.DOWN)) {
this.gotoAndStop(1);
}

is on the movieclip held in the first frame of the main movieclip and on frame 1 of this movieclip is the character standing in the position i want it to when it isnt moving.

DangerousDan
September 7th, 2006, 08:11 PM
Wait, are you using a movieclip within a movieclip? I can't really grasp the concept and I've read your explanation a few times, mind posting a FLA? I'm using MX 2004 at the moment, I'll do my best to help you with that.

slyerguy
September 7th, 2006, 08:26 PM
yes i am using a movieclip withing a movieclip and im not sure whether or not you could view the fla cause i use flash 8

DangerousDan
September 7th, 2006, 08:38 PM
Alrighty then, I'll just start shooting out questions then...
If you hold down the Down key does it play any sort of animation? Add a few trace statements inside the if statements to find out what is happening.

slyerguy
September 7th, 2006, 10:02 PM
i did some traces and everything is happening when it should but i noticed that when you move down the first time, the animation plays correctly and if you realease down, the character stops the animation and stands still but if you press the down key again before moving in any other direction, the character will move down but will not start the animation again.

slyerguy
September 8th, 2006, 05:55 PM
i solved the problem so i wont need any more help. what i did was add another 4 frames with the character standing still and instead of using

onClipEvent (enterFrame) {
if (!Key.isDown(Key.DOWN)) {
this.gotoAndStop(1);
}
}

i used

onClipEvent (enterFrame) {
if (!Key.isDown(Key.DOWN)) {
_root.character.gotoAndStop(5);
}
}

DangerousDan
September 8th, 2006, 07:30 PM
Good to hear, I was going to suggest something like that _root.character part.