Skip to content

Commit

Permalink
Merge pull request #15 from innogames/support-properties-for-motion-a…
Browse files Browse the repository at this point in the history
…ctuators_and_support-startsat-property

Supporting properties for motion path actuactors. Also adding the sta…
  • Loading branch information
Tobbse authored Feb 23, 2024
2 parents 4005aee + 3f10550 commit 80b958f
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 80b958f

Please sign in to comment.