I have a function that could be called many times, but I don't want it to be executed more than once per frame. What's the best way of implementing that?
CodePudding user response:
Something like a trigger switch you reset once per frame. I believe the script below is self-explanatory enough.
var canTrigger:Boolean;
addEventListener(Event.ENTER_FRAME, resetTrigger);
function resetTrigger(e:Event):void
{
canTrigger = true;
}
function oncePerFrame():void
{
if (!canTrigger) return;
canTrigger = false;
// Your code from here on.
}