diff --git a/src/motion/actuators/GenericActuator.hx b/src/motion/actuators/GenericActuator.hx index cae064b..b2e4438 100644 --- a/src/motion/actuators/GenericActuator.hx +++ b/src/motion/actuators/GenericActuator.hx @@ -451,6 +451,13 @@ class GenericActuator implements IGenericActuator { + } + + + public function goto (position:Float):Void { + + + } diff --git a/src/motion/actuators/IGenericActuator.hx b/src/motion/actuators/IGenericActuator.hx index dc93d66..b8a605c 100644 --- a/src/motion/actuators/IGenericActuator.hx +++ b/src/motion/actuators/IGenericActuator.hx @@ -103,6 +103,12 @@ interface IGenericActuator { */ public function onResume (handler:Dynamic, ?parameters:Array ):IGenericActuator; + /** + * Adjusts the tween to a specific position. + * @param position The new position of the tween, between 0.0 and 1.0 + */ + public function goto (position:Float):Void; + //private var properties:Dynamic; private function apply ():Void; diff --git a/src/motion/actuators/MethodActuator.hx b/src/motion/actuators/MethodActuator.hx index 855286a..6461a3e 100644 --- a/src/motion/actuators/MethodActuator.hx +++ b/src/motion/actuators/MethodActuator.hx @@ -85,22 +85,18 @@ class MethodActuator extends SimpleActuator { } - private override function update (currentTime:Float):Void { + public override function goto (position:Float):Void { - super.update (currentTime); + super.goto (position); - if (active && !paused) { - - for (i in 0...properties.start.length) { - - currentParameters[i] = Reflect.field (tweenProperties, "param" + i); - - } + for (i in 0...properties.start.length) { - callMethod (target, currentParameters); + currentParameters[i] = Reflect.field (tweenProperties, "param" + i); } + callMethod (target, currentParameters); + } diff --git a/src/motion/actuators/SimpleActuator.hx b/src/motion/actuators/SimpleActuator.hx index a97538b..6ab84aa 100644 --- a/src/motion/actuators/SimpleActuator.hx +++ b/src/motion/actuators/SimpleActuator.hx @@ -425,95 +425,100 @@ class SimpleActuator extends GenericActuator { } } - - - private function update (currentTime:Float):Void { - - if (!paused) { + + override public function goto (tweenPosition:Float):Void { - var details:PropertyDetails; - var easing:Float; - var i:Int; + var details:PropertyDetails; + var easing:Float; + var i:Int; - var tweenPosition:Float = (currentTime - timeOffset) / duration; + if (!initialized) { - if (tweenPosition > 1) { + initialize (); + + } + + if (!special) { + + easing = _ease.calculate (tweenPosition); + + for (i in 0...detailsLength) { - tweenPosition = 1; + details = propertyDetails[i]; + setProperty (details, details.start + (details.change * easing)); } - if (!initialized) { + } else { + + if (!_reverse) { + + easing = _ease.calculate (tweenPosition); + + } else { - initialize (); + easing = _ease.calculate (1 - tweenPosition); } - if (!special) { + var endValue:Float; + + for (i in 0...detailsLength) { - easing = _ease.calculate (tweenPosition); + details = propertyDetails[i]; - for (i in 0...detailsLength) { + if (_smartRotation && (details.propertyName == "rotation" || details.propertyName == "rotationX" || details.propertyName == "rotationY" || details.propertyName == "rotationZ")) { - details = propertyDetails[i]; - setProperty (details, details.start + (details.change * easing)); + var rotation:Float = details.change % 360; - } - - } else { - - if (!_reverse) { + if (rotation > 180) { + + rotation -= 360; + + } else if (rotation < -180) { + + rotation += 360; + + } - easing = _ease.calculate (tweenPosition); + endValue = details.start + rotation * easing; } else { - easing = _ease.calculate (1 - tweenPosition); + endValue = details.start + (details.change * easing); } - var endValue:Float; - - for (i in 0...detailsLength) { + if (!_snapping) { - details = propertyDetails[i]; + setProperty (details, endValue); - if (_smartRotation && (details.propertyName == "rotation" || details.propertyName == "rotationX" || details.propertyName == "rotationY" || details.propertyName == "rotationZ")) { - - var rotation:Float = details.change % 360; - - if (rotation > 180) { - - rotation -= 360; - - } else if (rotation < -180) { - - rotation += 360; - - } - - endValue = details.start + rotation * easing; - - } else { - - endValue = details.start + (details.change * easing); - - } + } else { - if (!_snapping) { - - setProperty (details, endValue); - - } else { - - setProperty (details, Math.round (endValue)); - - } + setProperty (details, Math.round (endValue)); } } + } + } + + + private function update (currentTime:Float):Void { + + if (!paused) { + + var tweenPosition:Float = (currentTime - timeOffset) / duration; + + if (tweenPosition > 1) { + + tweenPosition = 1; + + } + + goto (tweenPosition); + if (tweenPosition == 1) { if (_repeat == 0) {