Last active
August 29, 2015 14:18
-
-
Save aberloni/08cf7286fa1836862cdb to your computer and use it in GitHub Desktop.
Flash AS3 simple delta time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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