From e9ac7d6b7a3dda17489382146be7252d61354333 Mon Sep 17 00:00:00 2001 From: "nenad.bojkovski" Date: Fri, 1 Jun 2018 17:43:20 +0200 Subject: [PATCH 1/2] Restarting of an actuator implemented so that actuators can be reused --- src/motion/Actuate.hx | 12 +++++ src/motion/actuators/GenericActuator.hx | 15 +++++- src/motion/actuators/IGenericActuator.hx | 7 +++ src/motion/actuators/SimpleActuator.hx | 63 ++++++++++++++++++------ 4 files changed, 82 insertions(+), 15 deletions(-) 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..fe33b08 100644 --- a/src/motion/actuators/GenericActuator.hx +++ b/src/motion/actuators/GenericActuator.hx @@ -146,6 +146,8 @@ class GenericActuator implements IGenericActuator { private function complete (sendEvent:Bool = true):Void { + Actuate.unload (this); + if (sendEvent) { change (); @@ -158,7 +160,6 @@ class GenericActuator implements IGenericActuator { } - Actuate.unload (this); } @@ -177,6 +178,18 @@ 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 = true):GenericActuator { + + return this; + + } + + /** * 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/IGenericActuator.hx b/src/motion/actuators/IGenericActuator.hx index dc93d66..da0ac2c 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 = true):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..e5cfb14 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,36 @@ class SimpleActuator extends GenericActuator { } + /** + * @inheritDoc + */ + public override function restart (includeDelay:Bool = true):GenericActuator { + + 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) From 9cd3b65446683132f6532535a93a60351548f62a Mon Sep 17 00:00:00 2001 From: "nenad.bojkovski" Date: Mon, 4 Jun 2018 15:03:58 +0200 Subject: [PATCH 2/2] Restart repeat/reverse tween --- src/motion/actuators/GenericActuator.hx | 11 ++++++++--- src/motion/actuators/IGenericActuator.hx | 2 +- src/motion/actuators/SimpleActuator.hx | 4 +++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/motion/actuators/GenericActuator.hx b/src/motion/actuators/GenericActuator.hx index fe33b08..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; @@ -183,8 +185,11 @@ class GenericActuator implements IGenericActuator { * @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 = true):GenericActuator { - + public function restart (includeDelay:Bool = false):GenericActuator { + + _reverse = false; + _repeat = _repeatTimes; + return this; } @@ -381,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 da0ac2c..e4e7116 100644 --- a/src/motion/actuators/IGenericActuator.hx +++ b/src/motion/actuators/IGenericActuator.hx @@ -26,7 +26,7 @@ interface IGenericActuator { * @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 = true):IGenericActuator; + public function restart (includeDelay:Bool = false):IGenericActuator; /** * Sets the easing which is used when running the tween diff --git a/src/motion/actuators/SimpleActuator.hx b/src/motion/actuators/SimpleActuator.hx index e5cfb14..c884f5f 100644 --- a/src/motion/actuators/SimpleActuator.hx +++ b/src/motion/actuators/SimpleActuator.hx @@ -168,7 +168,9 @@ class SimpleActuator extends GenericActuator { /** * @inheritDoc */ - public override function restart (includeDelay:Bool = true):GenericActuator { + public override function restart (includeDelay:Bool = false):GenericActuator { + + super.restart (includeDelay); startTime = __getPlatformTime (); timeOffset = startTime + (includeDelay ? _delay : 0);