Hello,
I have tried and failed to figure out how to do this: I have an arrow (Sprite) that I want to rotate right continuously when I press the right arrow, and likewise left for the left arrow, and stop when I release the key.
Here is my code:
private var arrowRight:TweenMax;
private var arrowLeft:TweenMax;
// ...
arrowRight = new TweenMax(arrow, 3, {rotation:360, repeat:-1, ease:Linear.easeNone, paused:true});
arrowLeft = new TweenMax(arrow, 3, {rotation:-360, repeat:-1, ease:Linear.easeNone, paused:true});
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
private function keyPressed(k:KeyboardEvent):void {
if (k.keyCode == 39) {
arrowRight.play();
} else if (k.keyCode == 37) {
arrowLeft.play();
}
}
private function keyReleased(k:KeyboardEvent):void {
if (k.keyCode == 39) {
arrowRight.pause();
} else if (k.keyCode == 37) {
arrowLeft.pause();
}
}
The problem with this (as you probably would guess) is that if I first press RIGHT, then when I release and press LEFT, the arrow rotates left until it gets to rotation=0, then jumps to the rotation value that it was at when I released RIGHT. If I hold LEFT down, it does the jump every time it hits rotation=0.
How do I fix this so that rotation starts and continues seamlessly in either direction?
Thanks!
Tim