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

IGenericActuator: added goto() method that can manually change the current position #104

Open
wants to merge 2 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
7 changes: 7 additions & 0 deletions src/motion/actuators/GenericActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ class GenericActuator<T> implements IGenericActuator {



}


public function goto (position:Float):Void {



}


Expand Down
6 changes: 6 additions & 0 deletions src/motion/actuators/IGenericActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ interface IGenericActuator {
*/
public function onResume (handler:Dynamic, ?parameters:Array <Dynamic>):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;
Expand Down
16 changes: 6 additions & 10 deletions src/motion/actuators/MethodActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,18 @@ class MethodActuator<T> extends SimpleActuator<T, T> {
}


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);

}


Expand Down
123 changes: 64 additions & 59 deletions src/motion/actuators/SimpleActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -425,95 +425,100 @@ class SimpleActuator<T, U> extends GenericActuator<T> {
}

}


private function update (currentTime:Float):Void {

if (!paused) {

override public function goto (tweenPosition:Float):Void {

var details:PropertyDetails<U>;
var easing:Float;
var i:Int;
var details:PropertyDetails<U>;
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) {
Expand Down