actionscript 3 - AS3.0 if/else if evaluation behaviour for velocity control -
sorry if obvious others, can't head around in actionscript 3.0 (huge n00b btw)
i have code controlling velocity:
public function keydownhandler(event:keyboardevent):void { if (event.keycode == keyboard.left) { vx = -5; } else if (event.keycode == keyboard.right) { vx = 5; } else if (event.keycode == keyboard.up) { vy = -5 } else if (event.keycode == keyboard.down) { vy = 5; } }
when run, if hold both left , sprite moves diagonally, fact 2 lastly conditionals (keyboard.up & keyboard.down) elseifs should prevent them beingness evaluated @ shouldnt it?
is able shed lite on behaviour?
when press both buttons flash fires 2 independent events each button. if want skip case, can create state flags (leftpressed, rightpressed, etc) each button, alter state in key handler , phone call check motion method according current states of each button.
actionscript-3 flash if-statement conditional velocity
No comments:
Post a Comment