summaryrefslogtreecommitdiff
path: root/examples/game-controller.scm
diff options
context:
space:
mode:
authorAlex McGrath <alexmcgrath@fastmail.com>2019-05-28 21:43:49 +0100
committerDavid Thompson <dthompson2@worcester.edu>2019-05-28 18:03:40 -0400
commit12ac60e9caecb5e6ababdded9ba9f8e73c7cb742 (patch)
tree538ef0aea175d6f5eae46fa3033e12c45b61b01c /examples/game-controller.scm
parent834c25dbbf705a5541bd83d97bf29f711087ddc4 (diff)
Update a couple of examples to use new sprite batch API.
* examples/game-controller.scm: Use new sprite batch API. * examples/grid.scm: Ditto.
Diffstat (limited to 'examples/game-controller.scm')
-rw-r--r--examples/game-controller.scm42
1 files changed, 25 insertions, 17 deletions
diff --git a/examples/game-controller.scm b/examples/game-controller.scm
index 252f368..77a0ac0 100644
--- a/examples/game-controller.scm
+++ b/examples/game-controller.scm
@@ -6,6 +6,7 @@
(chickadee render texture)
(ice-9 match))
+(define batch #f)
(define controller #f)
(define atlas #f)
(define button-icons
@@ -36,23 +37,26 @@
(define (load)
(set! no-controller-msg-pos (vec2 (center-text no-controller-msg) 240.0))
- (set! atlas (split-texture (load-image "images/controller-buttons.png")
- 80 80)))
+ (let ((texture (load-image "images/controller-buttons.png")))
+ (set! atlas (split-texture texture 80 80))
+ (set! batch (make-sprite-batch texture))))
(define (controller-add new-controller)
(set! controller (or controller new-controller))
(set! controller-name-pos
(vec2 (center-text (controller-name controller)) 440.0)))
-
(define (draw alpha)
(if controller
- (with-batched-sprites
- (draw-text (controller-name controller) controller-name-pos)
- (for-each (match-lambda
+ (begin
+ (sprite-batch-clear! batch)
+ (draw-text (controller-name controller) controller-name-pos)
+ (for-each (match-lambda
((axis p tile)
(let ((alpha (controller-axis controller axis)))
- (draw-sprite (texture-atlas-ref atlas tile) p
- #:tint (color 1.0 1.0 1.0 alpha)))))
+ (sprite-batch-add!
+ batch p
+ #:texture-region (texture-atlas-ref atlas tile)
+ #:tint (color 1.0 1.0 1.0 alpha)))))
trigger-icons)
(for-each (match-lambda
(((and (or 'left-stick 'right-stick) button)
@@ -67,19 +71,23 @@
(if (eq? button 'left-stick)
'left-y
'right-y))))
- (draw-sprite (texture-atlas-ref atlas released)
- p)
+ (sprite-batch-add! batch p
+ #:texture-region (texture-atlas-ref atlas released))
(when (or pressed? (not (zero? x)) (not (zero? y)))
- (draw-sprite (texture-atlas-ref atlas pressed)
- (vec2+ p (vec2 (* x 16.0) (* y -16.0)))))))
+ (sprite-batch-add!
+ batch
+ (vec2+ p (vec2 (* x 16.0) (* y -16.0)))
+ #:texture-region (texture-atlas-ref atlas pressed)))))
((button p released pressed)
(let ((pressed? (controller-button-pressed? controller
button)))
- (draw-sprite (texture-atlas-ref
- atlas
- (if pressed? pressed released))
- p))))
- button-icons))
+ (sprite-batch-add!
+ batch p
+ #:texture-region
+ (texture-atlas-ref atlas
+ (if pressed? pressed released))))))
+ button-icons)
+ (draw-sprite-batch batch))
(draw-text no-controller-msg no-controller-msg-pos)))
(run-game #:load load #:draw draw #:controller-add controller-add)