diff options
-rw-r--r-- | starling/node-2d.scm | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/starling/node-2d.scm b/starling/node-2d.scm index c71d4e8..df434f8 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -88,6 +88,10 @@ atlas index + <animation> + frames + frame-duration + <animated-sprite> animations frame-duration @@ -522,11 +526,13 @@ ;;; Animated Sprite ;;; +(define-class <animation> () + (frames #:getter frames #:init-keyword #:frames) + (frame-duration #:getter frame-duration #:init-keyword #:frame-duration + #:init-form 250)) + (define-class <animated-sprite> (<atlas-sprite>) (animations #:accessor animations #:init-keyword #:animations) - (frame-duration #:accessor frame-duration - #:init-keyword #:frame-duration - #:init-form 500) (current-animation #:accessor current-animation #:init-keyword #:default-animation #:init-form 'default) @@ -537,10 +543,11 @@ (define-method (update (sprite <animated-sprite>) dt) (let* ((anim (assq-ref (animations sprite) (current-animation sprite))) - (frame-duration (frame-duration sprite)) - (anim-duration (* frame-duration (vector-length anim))) + (frame-duration (frame-duration anim)) + (frames (frames anim)) + (anim-duration (* frame-duration (vector-length frames))) (time (modulo (- (elapsed-time) (start-time sprite)) anim-duration)) - (frame (vector-ref anim (floor (/ time frame-duration))))) + (frame (vector-ref frames (floor (/ time frame-duration))))) (set! (index sprite) frame) (next-method))) |