Skip to content

Commit

Permalink
Add option to delay overwrite until tween initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
chatziko committed Jun 19, 2020
1 parent 8040df0 commit 3f02095
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/motion/Actuate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Actuate {

public static var defaultActuator:Class<IGenericActuator> = SimpleActuator;
public static var defaultEase:IEasing = Expo.easeOut;
public static var delayOverwrite = false;
private static var targetLibraries = new ObjectMap<Dynamic, Array<IGenericActuator>> ();
#if neko
private static var methodLibraries = new FunctionMap<Dynamic, Array<IGenericActuator>> ();
Expand Down Expand Up @@ -415,21 +416,22 @@ class Actuate {

var actuator:GenericActuator<T> = Type.createInstance (customActuator, [ target, duration, properties ]);
var library = getLibrary (actuator.target);
library.push (actuator);

if (overwrite) {

var i = library.length - 1;

while (i >= 0) {
library[i].stop (actuator.properties, false, false);
i--;
if (delayOverwrite) {

actuator.delayOverwrite = true;

} else {

doOverwrite (actuator);

}

library = getLibrary (actuator.target);

}

library.push (actuator);
actuator.move ();

return actuator;
Expand All @@ -446,6 +448,21 @@ class Actuate {

}


@:allow(motion.actuators)
private static function doOverwrite<T> (actuator:GenericActuator<T>):Void {

// only overwrite actuators created earlier than ours
var library = getLibrary (actuator.target);
var i = library.indexOf (actuator) - 1;

while (i >= 0) {
library[i].stop (actuator.properties, false, false);
i--;
}

}


/*@:generic*/ public static function unload<T> (actuator:GenericActuator<T>):Void {

Expand Down
2 changes: 2 additions & 0 deletions src/motion/actuators/GenericActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GenericActuator<T> implements IGenericActuator {
private var _smartRotation:Bool;
private var _snapping:Bool;
private var special:Bool;
private var delayOverwrite:Bool;


public function new (target:T, duration:Float, properties:Dynamic) {
Expand All @@ -45,6 +46,7 @@ class GenericActuator<T> implements IGenericActuator {
_smartRotation = false;
_snapping = false;
special = false;
delayOverwrite = false;

this.target = target;
this.properties = properties;
Expand Down
6 changes: 6 additions & 0 deletions src/motion/actuators/SimpleActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ class SimpleActuator<T, U> extends GenericActuator<T> {

var details:PropertyDetails<U>;
var start:Dynamic;

if (delayOverwrite) {

Actuate.doOverwrite (this);

}

for (i in Reflect.fields (properties)) {

Expand Down

0 comments on commit 3f02095

Please sign in to comment.