summaryrefslogtreecommitdiff
path: root/examples/game-controller.scm
diff options
context:
space:
mode:
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)