diff --git a/src/motion/actuators/SimpleActuator.hx b/src/motion/actuators/SimpleActuator.hx index 706029a..20a286e 100644 --- a/src/motion/actuators/SimpleActuator.hx +++ b/src/motion/actuators/SimpleActuator.hx @@ -31,7 +31,8 @@ class SimpleActuator extends GenericActuator { private static var actuators = new Array> (); private static var actuatorsLength = 0; - private static var addedEvent = false; + private static var time:Float; + private static var timerInitialized: Bool; #if (!flash && !nme && !openfl && !lime && !js) private static var timer:Timer; @@ -49,9 +50,31 @@ class SimpleActuator extends GenericActuator { private var startTime:Float; private var toggleVisible:Bool; + private static function setup() + { + if (timerInitialized) + return; + + timerInitialized = true; + + #if !actuate_manual_update + #if (flash || nme || openfl) + Lib.current.stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame); + #elseif lime + Application.current.onUpdate.add(stage_onEnterFrame); + #elseif js + Browser.window.requestAnimationFrame(stage_onEnterFrame); + #else + timer = new Timer(Std.int(1000 / 30)); + timer.run = stage_onEnterFrame; + #end + #end + } public function new (target:T, duration:Float, properties:Dynamic) { + setup(); + active = true; propertyDetails = new Array (); sendChange = false; @@ -61,39 +84,9 @@ class SimpleActuator extends GenericActuator { setVisible = false; toggleVisible = false; - #if !actuate_manual_time - #if (flash || nme || openfl) - startTime = Lib.getTimer () / 1000; - #elseif lime - startTime = System.getTimer () / 1000; - #elseif js - startTime = Browser.window.performance.now () / 1000; - #else - startTime = Timer.stamp (); - #end - #else - startTime = getTime(); - #end + startTime = time; super (target, duration, properties); - - if (!addedEvent) { - - addedEvent = true; - #if !actuate_manual_update - #if (flash || nme || openfl) - Lib.current.stage.addEventListener (Event.ENTER_FRAME, stage_onEnterFrame); - #elseif lime - Application.current.onUpdate.add (stage_onEnterFrame); - #elseif js - Browser.window.requestAnimationFrame(stage_onEnterFrame); - #else - timer = new Timer (Std.int(1000 / 30)); - timer.run = stage_onEnterFrame; - #end - #end - } - } //For instant transition to start state without shaking @@ -621,6 +614,8 @@ class SimpleActuator extends GenericActuator { #else var currentTime = getTime (); #end + + time = currentTime; var actuator:SimpleActuator;