var lastRecordedTime:Number = getTimer();
while(getTimer()>lastRecordedTime+10000)
{
}
I want to put my game on a wait state. Should I use while loop like this or is there a more performance efficient way of doing this?
var lastRecordedTime:Number = getTimer();
while(getTimer()>lastRecordedTime+10000)
{
}
I want to put my game on a wait state. Should I use while loop like this or is there a more performance efficient way of doing this?
Never use an approach like this in AS3. AS3 has a serious shortcoming in that it doesn't support multi-threading. This crashes the program completely as long as that timer keeps running, and Windows 7 in particular will freak out if the user keeps trying to click it or something.
Try this:
private var m_tmr:Timer = new Timer(10000, 1);
.
.
.
private function func():void
{
.
.
.
m_tmr.addEventListener(TimerEvent.TIMER, tick);
m_tmr.start();
}
private function tick(pEvent:TimerEvent):void
{
// pick back up in here
}
The only thing about this is that it's asynchronous, so you might have to add some special logic to ignore certain types of events and stuff in the meantime, depending on what you're trying to accomplish. But using a while loop to just sleep the thread isn't going to work out in AS3.