summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dave@izanagi>2013-06-16 14:37:27 -0400
committerDavid Thompson <dave@izanagi>2013-06-16 14:37:27 -0400
commit7210ad156678c89f3dc9a73e0adf7e50c50888a3 (patch)
treee1013473d969cb00d4d2b5ba94bbf418715b7665 /2d
parentc04b4b1ea000410c8fa64834043f7361dd7a7460 (diff)
Add color property to <sprite>.
Diffstat (limited to '2d')
-rw-r--r--2d/sprite.scm17
1 files changed, 11 insertions, 6 deletions
diff --git a/2d/sprite.scm b/2d/sprite.scm
index 0f18dd7..4415974 100644
--- a/2d/sprite.scm
+++ b/2d/sprite.scm
@@ -45,14 +45,15 @@
;; The <sprite> object represents a texture with a given position, scale, and
;; rotation.
(define-record-type <sprite>
- (make-sprite texture x y scale-x scale-y rotation)
+ (make-sprite texture x y scale-x scale-y rotation color)
sprite?
(texture sprite-texture)
(x sprite-x set-sprite-x!)
(y sprite-y set-sprite-y!)
(scale-x sprite-scale-x set-sprite-scale-x!)
(scale-y sprite-scale-y set-sprite-scale-y!)
- (rotation sprite-rotation set-sprite-rotation!))
+ (rotation sprite-rotation set-sprite-rotation!)
+ (color sprite-color set-sprite-color!))
(define (set-sprite-scale! sprite scale)
"Sets sprite scale-x and scale-y to the same value."
@@ -61,15 +62,19 @@
(define (load-sprite filename)
"Loads a sprite from file with default position, scaling, and rotation values."
- (make-sprite (load-texture filename) 0 0 1 1 0))
+ (make-sprite (load-texture filename) 0 0 1 1 0 '(1 1 1)))
(define (draw-sprite sprite)
"Renders a sprite."
(let* ((texture (sprite-texture sprite))
- (w (texture-width texture))
- (h (texture-height texture)))
+ (width (texture-width texture))
+ (height (texture-height texture)))
(with-gl-push-matrix
(gl-translate (sprite-x sprite) (sprite-y sprite) 0)
(gl-rotate (sprite-rotation sprite) 0 0 1)
(gl-scale (sprite-scale-x sprite) (sprite-scale-y sprite) 0)
- (texture-quad texture (- (/ w 2)) (- (/ h 2)) w h))))
+ ;; Render a textured quad center on the sprite position.
+ (texture-quad texture
+ (- (/ width 2)) (- (/ height 2))
+ width height
+ (sprite-color sprite)))))