kaptain kosher
06-30-2009, 08:39 PM
I'm making a simple game to orient myself with AS3, and right now I have an arrow key controlled character that move around. Specifically I want to character to move when I push down an arrow key, then if I keep the original arrow key down and push down another direction the character will go in the new direction and if I let the new key go the character will resume moving in the original direction. No diagonal movement is allowed.
So far I have gotten this to work if I am holding down a vertical key (up, down) and push and let go of a horizontal key (left, right). However, if I'm holding down a horizontal key and tap a vertical key the character won't move in the new direction.
At the moment I'm using four booleans (tryingToMoveLeft, tryingToMoveRight, etc.), and event listeners. When I push down an arrow key the corresponding boolean is true, and when I let it go it becomes false. Then every frame, if a boolean is true then the character moves in that direction.
By changing around my if-else statements I have found that I can change the movement but I've tried what seems to be every combination and haven't gotten the desired results.
So far I have gotten this to work if I am holding down a vertical key (up, down) and push and let go of a horizontal key (left, right). However, if I'm holding down a horizontal key and tap a vertical key the character won't move in the new direction.
At the moment I'm using four booleans (tryingToMoveLeft, tryingToMoveRight, etc.), and event listeners. When I push down an arrow key the corresponding boolean is true, and when I let it go it becomes false. Then every frame, if a boolean is true then the character moves in that direction.
By changing around my if-else statements I have found that I can change the movement but I've tried what seems to be every combination and haven't gotten the desired results.