Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actuator restart #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/motion/Actuate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ class Actuate {
#end


private static function load<T> (actuator:GenericActuator<T>):Void {

var library = getLibrary (actuator.target);
if (library.indexOf (actuator) == -1) {

library.push (actuator);

}

}


private static function getLibrary<T> (target:T, allowCreation:Bool = true):Array<IGenericActuator> {

#if neko
Expand Down
22 changes: 20 additions & 2 deletions src/motion/actuators/GenericActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GenericActuator<T> implements IGenericActuator {
private var _onPauseParams:Array <Dynamic>;
private var _reflect:Bool;
private var _repeat:Int;
private var _repeatTimes:Int;
private var _reverse:Bool;
private var _smartRotation:Bool;
private var _snapping:Bool;
Expand All @@ -40,6 +41,7 @@ class GenericActuator<T> implements IGenericActuator {
_autoVisible = true;
_delay = 0;
_reflect = false;
_repeatTimes = 0;
_repeat = 0;
_reverse = false;
_smartRotation = false;
Expand Down Expand Up @@ -146,6 +148,8 @@ class GenericActuator<T> implements IGenericActuator {

private function complete (sendEvent:Bool = true):Void {

Actuate.unload (this);

if (sendEvent) {

change ();
Expand All @@ -158,7 +162,6 @@ class GenericActuator<T> implements IGenericActuator {

}

Actuate.unload (this);

}

Expand All @@ -177,6 +180,21 @@ class GenericActuator<T> 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<T> {

_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
Expand Down Expand Up @@ -368,7 +386,7 @@ class GenericActuator<T> implements IGenericActuator {
times = -1;

}

_repeatTimes = times;
_repeat = times;

return this;
Expand Down
7 changes: 7 additions & 0 deletions src/motion/actuators/IGenericActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 51 additions & 14 deletions src/motion/actuators/SimpleActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import haxe.PosInfos;
import haxe.Timer;
#end


@:access(motion.Actuate)
class SimpleActuator<T, U> extends GenericActuator<T> {


Expand Down Expand Up @@ -61,19 +61,7 @@ class SimpleActuator<T, U> extends GenericActuator<T> {
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);

Expand All @@ -96,6 +84,23 @@ class SimpleActuator<T, U> extends GenericActuator<T> {

}

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
Expand Down Expand Up @@ -160,6 +165,38 @@ class SimpleActuator<T, U> extends GenericActuator<T> {
}


/**
* @inheritDoc
*/
public override function restart (includeDelay:Bool = false):GenericActuator<T> {

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<V> (target:V, propertyName:String):Dynamic {

#if (haxe_209 || haxe3)
Expand Down