From 4552c880a6fd30f5bd87ce101491e0e966c42d77 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 11 Jun 2019 09:19:34 -0400 Subject: node-2d: sprite: Allow overriding texcoords and destination rectangle. --- starling/node-2d.scm | 26 +++++++++++++++++++++++--- 1 file 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 @@ texture + texcoords + rect blend-mode tint @@ -465,9 +467,15 @@ (define-generic texture) +(define-method (texcoords (sprite )) + (texture-gl-tex-rect (asset-ref (texture sprite)))) + +(define-method (rect (sprite )) + (texture-gl-rect (asset-ref (texture sprite)))) + (define-method (render (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 () - (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 )) + (or (slot-ref sprite 'texcoords) + (next-method))) + +(define-method (rect (sprite )) + (or (slot-ref sprite 'rect) + (next-method))) ;;; -- cgit v1.2.3