summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-08-18 07:31:28 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-08-25 19:33:08 -0400
commit21ba5fa077f01897f358e13444e911737fa6271a (patch)
tree32264ebcf6b37784e44f2ba4caca47b00026d9ab
parent8d6b96b91251f62cb063bf6ec38933ed457a1d7f (diff)
Add make-animated-sprite procedure.
* sly/sprite.scm (make-animated-sprite): New procedure.
-rw-r--r--sly/sprite.scm29
1 files changed, 26 insertions, 3 deletions
diff --git a/sly/sprite.scm b/sly/sprite.scm
index f92687f..59583db 100644
--- a/sly/sprite.scm
+++ b/sly/sprite.scm
@@ -24,17 +24,20 @@
(define-module (sly sprite)
#:use-module (srfi srfi-1)
- #:use-module (srfi srfi-9)
- #:use-module (srfi srfi-9 gnu)
+ #:use-module (srfi srfi-26)
#:use-module (gl)
#:use-module (gl contrib packed-struct)
#:use-module ((sdl sdl) #:prefix SDL:)
#:use-module (sly config)
+ #:use-module (sly agenda)
+ #:use-module (sly helpers)
#:use-module (sly math)
#:use-module (sly mesh)
#:use-module (sly shader)
+ #:use-module (sly signal)
#:use-module (sly texture)
- #:export (make-sprite))
+ #:export (make-sprite
+ make-animated-sprite))
;;;
;;; Sprites
@@ -61,3 +64,23 @@
(vector s2 t1)
(vector s2 t2)
(vector s1 t2)))))))
+
+(define* (make-animated-sprite textures frame-duration #:optional #:key
+ (loop? #t)
+ (shader (load-default-shader)))
+ "Return a signal that iterates through the list TEXTURES and
+displays them each for FRAME-DURATION ticks. The optional LOOP? flag
+specifies if the animation should play once or indefinitely.
+Optionally, a SHADER can be specified, otherwise the default mesh
+shader is used."
+ (let ((frames (map (cut make-sprite <> #:shader shader) textures)))
+ (signal-generator
+ (define (animate)
+ (for-each (lambda (frame)
+ (yield frame)
+ (wait frame-duration))
+ frames))
+
+ (if loop?
+ (forever (animate))
+ (animate)))))