PDA

View Full Version : [AS2] Game character movement question.


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.

christian07
03-07-2007, 08:55 PM
No one has been able to answer my question but it seems really simple and I'm not advanced in ActionScript. I'm making a game with the view angle of Legend of Zelda for SNES. I want to know the code to make my character move in this specific way. I know how to make him move and rotate but I don't want that. I want the "hero" clip to go to the nested label "WalkCycleRight" when the right arrow key is pressed. Then, when the key is released I want the "hero" clip to go to the label "StandRight" where he is (not rotated or flipped but a new drawing) facing right. The same with left, up and down arrows keys. Try your suggestions first because what seems like it should work hasn't worked so far.

newblack
03-07-2007, 09:26 PM
what you're asking is too specific in terms of description and far too general in the scope of how to code something. what i'm saying is that you're asking the wrong question.

what is your problem? handling keyboard events? targeting a nested MovieClip? swapping MovieClips? You see the issue is that all of these subsequent questions are fair and thusly it's impossible to give you a concise answer.

my suggestion is to either rethink and rephrase your question or abandon the VERY specific way you'd like your animation to work and look at this: http://board.flashkit.com/board/showthread.php?t=706063

rrh
03-07-2007, 09:56 PM
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.The reason I think this doesn't work is that you are testing only if the Right arrow is down, but you should execute this only if none of the arrow keys are down.