From 3f10550c28e1bc893287adee53ec3bc7cd401ad8 Mon Sep 17 00:00:00 2001 From: Tobias Jansing Date: Mon, 19 Feb 2024 13:19:04 +0100 Subject: [PATCH] Supporting properties for motion path actuactors. Also adding the startsAt property so we can start animations at a certain progress. --- src/motion/actuators/MotionPathActuator.hx | 36 +++++++++++++++------- src/motion/actuators/SimpleActuator.hx | 5 +++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/motion/actuators/MotionPathActuator.hx b/src/motion/actuators/MotionPathActuator.hx index a76589b..8438ea7 100644 --- a/src/motion/actuators/MotionPathActuator.hx +++ b/src/motion/actuators/MotionPathActuator.hx @@ -18,24 +18,38 @@ class MotionPathActuator extends SimpleActuator { } 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; 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); + } } } diff --git a/src/motion/actuators/SimpleActuator.hx b/src/motion/actuators/SimpleActuator.hx index 808fd04..14070ff 100644 --- a/src/motion/actuators/SimpleActuator.hx +++ b/src/motion/actuators/SimpleActuator.hx @@ -352,6 +352,11 @@ class SimpleActuator extends GenericActuator { tweenPosition = (currentTime - timeOffset) / duration; + var startAt = getField(properties, "startAt"); + if (startAt != null) { + tweenPosition += startAt; + } + if (tweenPosition > 1) { tweenPosition = 1; }