I do something like this.
By doing the above the you get a smooth transition each frame based on user interaction.Code:var movingLeft:Boolean = false; stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); stage.addEventListener(KeyboardEvent.KEY_UP, keyUp); //will cause the function enterFrameHandler to be fired every frame stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler); //will execute when any key in pushed down function keyDown(e:KeyboardEvent):void { if(e.keyCode == 37) { movingLeft = true; } } //will execute when any key is let go, up function keyUp(e:KeyboardEvent):void { if(e.keyCode == 37) { movingLeft = false; } } //is executed every frame function enterFrameHandler(event:Event):void{ if(movingLeft == true){ object.x -= 10; } //I usually check if the object at object.y + 10 has collided with a tile //before moving the object down. object.y += 10; }
Above code wasn't tested.




Reply With Quote
