diff --git a/src/motion/Actuate.hx b/src/motion/Actuate.hx index 79c7587..a2a85f7 100644 --- a/src/motion/Actuate.hx +++ b/src/motion/Actuate.hx @@ -73,6 +73,18 @@ class Actuate { #end + private static function load (actuator:GenericActuator):Void { + + var library = getLibrary (actuator.target); + if (library.indexOf (actuator) == -1) { + + library.push (actuator); + + } + + } + + private static function getLibrary (target:T, allowCreation:Bool = true):Array { #if neko diff --git a/src/motion/actuators/GenericActuator.hx b/src/motion/actuators/GenericActuator.hx index 1ca928e..655cff4 100644 --- a/src/motion/actuators/GenericActuator.hx +++ b/src/motion/actuators/GenericActuator.hx @@ -29,6 +29,7 @@ class GenericActuator implements IGenericActuator { private var _onPauseParams:Array ; private var _reflect:Bool; private var _repeat:Int; + private var _repeatTimes:Int; private var _reverse:Bool; private var _smartRotation:Bool; private var _snapping:Bool; @@ -40,6 +41,7 @@ class GenericActuator implements IGenericActuator { _autoVisible = true; _delay = 0; _reflect = false; + _repeatTimes = 0; _repeat = 0; _reverse = false; _smartRotation = false; @@ -146,6 +148,8 @@ class GenericActuator implements IGenericActuator { private function complete (sendEvent:Bool = true):Void { + Actuate.unload (this); + if (sendEvent) { change (); @@ -158,7 +162,6 @@ class GenericActuator implements IGenericActuator { } - Actuate.unload (this); } @@ -177,6 +180,21 @@ class GenericActuator implements IGenericActuator { } + /** + * Starts the tween from the begining + * @param includeDelay if the tween has delay this flag determines if the delay should be applied on restart or not + * @return The current actuator instance + */ + public function restart (includeDelay:Bool = false):GenericActuator { + + _reverse = false; + _repeat = _repeatTimes; + + return this; + + } + + /** * Sets the easing which is used when running the tween * @param easing An easing equation, like Elastic.easeIn or Quad.easeOut @@ -368,7 +386,7 @@ class GenericActuator implements IGenericActuator { times = -1; } - + _repeatTimes = times; _repeat = times; return this; diff --git a/src/motion/actuators/IGenericActuator.hx b/src/motion/actuators/IGenericActuator.hx index dc93d66..e4e7116 100644 --- a/src/motion/actuators/IGenericActuator.hx +++ b/src/motion/actuators/IGenericActuator.hx @@ -21,6 +21,13 @@ interface IGenericActuator { */ public function delay (duration:Float):IGenericActuator; + /** + * Starts the tween from the begining + * @param includeDelay if the tween has delay this flag determines if the delay should be applied on restart or not + * @return The current actuator instance + */ + public function restart (includeDelay:Bool = false):IGenericActuator; + /** * Sets the easing which is used when running the tween * @param easing An easing equation, like Elastic.easeIn or Quad.easeOut diff --git a/src/motion/actuators/SimpleActuator.hx b/src/motion/actuators/SimpleActuator.hx index 96dbbcf..c884f5f 100644 --- a/src/motion/actuators/SimpleActuator.hx +++ b/src/motion/actuators/SimpleActuator.hx @@ -19,7 +19,7 @@ import haxe.PosInfos; import haxe.Timer; #end - +@:access(motion.Actuate) class SimpleActuator extends GenericActuator { @@ -61,19 +61,7 @@ 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 = __getPlatformTime (); super (target, duration, properties); @@ -96,6 +84,23 @@ class SimpleActuator extends GenericActuator { } + private static function __getPlatformTime ():Float { + + #if !actuate_manual_time + #if (flash || nme || openfl) + return Lib.getTimer () / 1000; + #elseif lime + return System.getTimer () / 1000; + #elseif js + return Browser.window.performance.now () / 1000; + #else + return Timer.stamp (); + #end + #else + return getTime(); + #end + + } /** * @inheritDoc @@ -160,6 +165,38 @@ class SimpleActuator extends GenericActuator { } + /** + * @inheritDoc + */ + public override function restart (includeDelay:Bool = false):GenericActuator { + + super.restart (includeDelay); + + startTime = __getPlatformTime (); + timeOffset = startTime + (includeDelay ? _delay : 0); + for (i in 0...detailsLength) { + + var details = propertyDetails[i]; + setProperty (details, details.start); + + } + + if (!active && actuators.indexOf (this) == -1) { + + actuators.push (this); + ++actuatorsLength; + + } + + active = true; + + Actuate.load (this); + + return this; + + } + + private inline function getField (target:V, propertyName:String):Dynamic { #if (haxe_209 || haxe3)