summaryrefslogtreecommitdiff
path: root/starling
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2019-06-26 08:01:36 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2019-06-26 08:01:36 -0400
commita912ed9ac928ebd3fb27343ab9a6d5906a6b433e (patch)
tree9397d1a13024ec0241b921fba037ecf881f0e67a /starling
parent97488fd4bf7f3660f95087ca6af4563401ecc375 (diff)
node-2d: Add <animation> class.
Now each sprite animation can have its own frame duration.
Diffstat (limited to 'starling')
-rw-r--r--starling/node-2d.scm19
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)))