From 7210ad156678c89f3dc9a73e0adf7e50c50888a3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 16 Jun 2013 14:37:27 -0400 Subject: Add color property to . --- 2d/sprite.scm | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to '2d') 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 object represents a texture with a given position, scale, and ;; rotation. (define-record-type - (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))))) -- cgit v1.2.3