Hello everybody I am developing a game with starling and i want to set a timer for example every 2 sec i want something to happen. I used the juggler elapsed prop but i wonder is there a more effecient way to do that

thank you,

Khaled

有帮助吗?

解决方案

If this does not relate to animation, it is recommended to use a Timer for non-animated content.

Timer implementation would be higher performance than additional time calculations on enter frame handler.

If you are advancing Starling Jugglers, you can set the frame rate of the Juggler to every 2-seconds.

Jugglers also have delayCall in which you could infinitely loop every 2-seconds if your functor redundantly called delayCall:

juggler.delayCall(functor, 2.0);

To tie in to Starlings frame / render lifecycle, you can test time since your last call.

private var lastCallTime:int

protected function frameHandler():void
{
    var now:int = getTimer();
    var ellapsed:int = now - lastCallTime;
    if(ellapsed >= 2000)
    {
        /* execute implementation */
        lastCallTime = now;
    }
}

其他提示

Alternatively, you can use the "DelayedCall" class. It's easy to miss! ;-)

var delayedCall:DelayedCall = new DelayedCall(method, 2.0);
delayedCall.repeatCount = int.MAX_VALUE;
Starling.juggler.add(delayedCall);

function method():void
{
    trace("ping");
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top