christian07
03-05-2007, 10:03 PM
I'm making a game with a top down view like in The Legend of Zelda for SNES (not directly top down but at an angle). I want my character 'hero' to go to the walk cycle for the appropriate direction nested in the hero timeline when the arrow keys are pressed. Then, when that key is released I want him to stay facing that direction but go to the frame of him standing still. I can successfully do this with the "right" arrow key and but will play the first frame of the correct walk cycle when the other keys are pressed but when the keys are released it jump to the facing right standing still frame. The right key's code comes first so I think it's a compatibility issue with the other keys. Here is my code for the right key and it's the same for the other keys.
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+speed;
gotoAndPlay("WalkRight");
}
if (!Key.isDown(Key.RIGHT)) {
gotoAndStop("StandRight");
}
It makes sense that adding a variable "heroPosition" would work if when the key's are pressed have the variable be that key (ex. if right key is pressed heroPosition = "Right") and then make the second if statement for the key if (heroPosition = "Right" && !Key.isDown... etc. This doesn't work. P.S. First time poster.
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+speed;
gotoAndPlay("WalkRight");
}
if (!Key.isDown(Key.RIGHT)) {
gotoAndStop("StandRight");
}
It makes sense that adding a variable "heroPosition" would work if when the key's are pressed have the variable be that key (ex. if right key is pressed heroPosition = "Right") and then make the second if statement for the key if (heroPosition = "Right" && !Key.isDown... etc. This doesn't work. P.S. First time poster.