summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2019-06-11 09:19:34 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2019-06-11 09:19:34 -0400
commit4552c880a6fd30f5bd87ce101491e0e966c42d77 (patch)
tree2c7909943dff925fe2f94fd536bae1e63b58461d
parentdd243dd72e2b1dd6d190816d97e814a0a0187a43 (diff)
node-2d: sprite: Allow overriding texcoords and destination rectangle.
-rw-r--r--starling/node-2d.scm26
1 files changed, 23 insertions, 3 deletions
diff --git a/starling/node-2d.scm b/starling/node-2d.scm
index 663942c..cc0c85c 100644
--- a/starling/node-2d.scm
+++ b/starling/node-2d.scm
@@ -79,6 +79,8 @@
<sprite>
texture
+ texcoords
+ rect
blend-mode
tint
@@ -465,9 +467,15 @@
(define-generic texture)
+(define-method (texcoords (sprite <base-sprite>))
+ (texture-gl-tex-rect (asset-ref (texture sprite))))
+
+(define-method (rect (sprite <base-sprite>))
+ (texture-gl-rect (asset-ref (texture sprite))))
+
(define-method (render (sprite <base-sprite>) alpha)
(let* ((tex (asset-ref (texture sprite)))
- (rect (texture-gl-rect tex))
+ (rect (rect sprite))
(batch (batch sprite))
(tint (tint sprite))
(matrix (world-matrix sprite)))
@@ -475,7 +483,9 @@
(sprite-batch-add* batch rect matrix
#:tint tint
#:texture-region tex)
- (draw-sprite* tex rect matrix #:tint tint))))
+ (draw-sprite* tex rect matrix
+ #:tint tint
+ #:texcoords (texcoords sprite)))))
;;;
@@ -483,7 +493,17 @@
;;;
(define-class <sprite> (<base-sprite>)
- (texture #:accessor texture #:init-keyword #:texture))
+ (texture #:accessor texture #:init-keyword #:texture)
+ (texcoords #:init-keyword #:texcoords #:init-form #f)
+ (rect #:init-keyword #:rect #:init-form #f))
+
+(define-method (texcoords (sprite <sprite>))
+ (or (slot-ref sprite 'texcoords)
+ (next-method)))
+
+(define-method (rect (sprite <sprite>))
+ (or (slot-ref sprite 'rect)
+ (next-method)))
;;;