Skip to content

Commit

Permalink
Supporting properties for motion path actuactors. Also adding the sta…
Browse files Browse the repository at this point in the history
…rtsAt property so we can start animations at a certain progress.
  • Loading branch information
Tobias Jansing committed Feb 19, 2024
1 parent 4005aee commit 3f10550
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/motion/actuators/MotionPathActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,38 @@ class MotionPathActuator<T> extends SimpleActuator<T, T> {
}

private override function initialize() {
super.initialize();

// "x" and "y" are handled by `super.initialize()`, but there's custom behavior for those properties below,
// so we need to remove the details and rebuild them.
propertyDetails = [
for (detail in propertyDetails) {
if (detail.propertyName == "x" || detail.propertyName == "y") continue;
detail;
}
];
detailsLength = propertyDetails.length;

var details:PropertyPathDetails<T>;
var path:IComponentPath;

for (propertyName in Reflect.fields(properties)) {
path = cast(Reflect.field(properties, propertyName), IComponentPath);
if (propertyName == "x" || propertyName == "y") {
path = cast(Reflect.field(properties, propertyName), IComponentPath);

if (path != null) {
var isField = true;
if (path != null) {
var isField = true;

if (Reflect.hasField(target, propertyName)) {
path.start = Reflect.field(target, propertyName);
} else {
isField = false;
path.start = Reflect.getProperty(target, propertyName);
}
if (Reflect.hasField(target, propertyName)) {
path.start = Reflect.field(target, propertyName);
} else {
isField = false;
path.start = Reflect.getProperty(target, propertyName);
}

details = new PropertyPathDetails(target, propertyName, path, isField);
propertyDetails.push(details);
details = new PropertyPathDetails(target, propertyName, path, isField);
propertyDetails.push(details);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/motion/actuators/SimpleActuator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ class SimpleActuator<T, U> extends GenericActuator<T> {

tweenPosition = (currentTime - timeOffset) / duration;

var startAt = getField(properties, "startAt");
if (startAt != null) {
tweenPosition += startAt;
}

if (tweenPosition > 1) {
tweenPosition = 1;
}
Expand Down

0 comments on commit 3f10550

Please sign in to comment.