diff options
author | David Thompson <dthompson2@worcester.edu> | 2018-08-30 07:46:33 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2018-08-30 07:46:33 -0400 |
commit | a5e0a9378daaee6a04ce8e2298e9d87137ee6048 (patch) | |
tree | 34d83f0953c8e549d35ffd2dfea154882d30be9d | |
parent | bdb5f2c1f3f03177a214b23428813342661654cc (diff) |
node-2d: Add follow-bezier-path method.
-rw-r--r-- | starling/node-2d.scm | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/starling/node-2d.scm b/starling/node-2d.scm index ccbb17b..8e3cad6 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -21,6 +21,7 @@ ;;; Code: (define-module (starling node-2d) + #:use-module (chickadee math bezier) #:use-module (chickadee math easings) #:use-module (chickadee math matrix) #:use-module (chickadee math rect) @@ -67,6 +68,7 @@ rotate-to scale-by scale-to + follow-bezier-path <sprite> texture @@ -349,6 +351,22 @@ (define-method (scale-by (node <node-2d>) dsx dsy duration) (scale-by node dsx dsy duration smoothstep)) +(define-method (follow-bezier-path (node <node-2d>) path duration forward?) + (let ((p (position node)) + (path (if forward? path (reverse path)))) + (for-each (lambda (bezier) + (tween duration + (if forward? 0.0 1.0) + (if forward? 1.0 0.0) + (lambda (t) + (bezier-curve-point-at! p bezier t) + (dirty! node)) + #:ease linear)) + path))) + +(define-method (follow-bezier-path (node <node-2d>) path duration) + (follow-bezier-path node path duration #t)) + ;; Events (define-method (update* (node <node-2d>) dt) |