TimerEvent
, call event.updateAfterEvent()
to update the screen immediately.Use
getTimer()
when you are crunching numbers relative to time. Do not rely on Timer.delay
.updateAfterEvent()
In the event handler of
TimerEvent.TIMER
, you can use event.updateAfterEvent()
which updates the display list after the event is processed. Smaller values for the timer's delay, means more screen updates.This way, Flash Player doesn't have to wait for the next "frame". And things like movement will look smoother.
For example:
private function timerEventHandler(event:TimerEvent):void
{
player1.x += horizontalVelocity;
player1.y += verticalVelocity; event.updateAfterEvent();
}
getTimer()
You can specify the delay of a
Timer
. But Flash Player can't promise to update after exáctly the specified delay
. To be more accurate, you can keep track of how much time really passed using getTimer().
And adjust your variables accordingly.For example:
var elapsedTime:int;
var time:int;
private function timerEventHandler(event:TimerEvent):void
{
var currentTime:int = getTimer();
elapsedTime = currentTime - time;
time = currentTime;
var f:Number = elapsedTime / timer.delay;
player1.x += horizontalVelocity * f;
player1.y += verticalVelocity * f;
event.updateAfterEvent();
}
No comments:
Post a Comment