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

Add option to delay overwrite until tween initialization #101

Open
wants to merge 1 commit 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
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