Skip to content

Instantly share code, notes, and snippets.

@aberloni
Last active August 29, 2015 14:18
Show Gist options
  • Save aberloni/08cf7286fa1836862cdb to your computer and use it in GitHub Desktop.
Save aberloni/08cf7286fa1836862cdb to your computer and use it in GitHub Desktop.
Flash AS3 simple delta time
package
{
import flash.display.Stage;
import flash.events.Event;
import flash.utils.getTimer;
/**
* ...
* @author ...
*/
public class Time
{
static public var time:Number = 0;
static public var delta:Number = 0;
static public function init(stage:Stage = null):void {
delta = time = 0;
if (stage == null) {
trace("Time", "delta won't update, no stage");
return;
}
update();
update();
update();
stage.addEventListener(Event.ENTER_FRAME, update);
}
static public function update(evt:Event = null):void {
delta = (getTimer() - time) / 1000;
time = getTimer();
//Console.log("Time", "delta ? " + delta + ", time ? " + time);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment