diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-05-03 21:00:03 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-05-03 21:00:03 -0400 |
commit | 6233cb8aaebe552b82a1911482929db9e0716650 (patch) | |
tree | de30fbbf89f8fd12ddf00833477b2f62107695f2 | |
parent | 5fc2705ea64563e7bbdcab303e83fa97aeb9e02d (diff) |
scene: Improve background music handling.
-rw-r--r-- | starling/scene.scm | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/starling/scene.scm b/starling/scene.scm index cda1e4e..16630ba 100644 --- a/starling/scene.scm +++ b/starling/scene.scm @@ -55,21 +55,33 @@ (define-class <scene> (<node>) (background-music-source #:getter background-music-source - #:init-form (make-source #:loop? #t)) + #:init-thunk make-source) (background-music #:accessor background-music #:init-form #f - #:init-keyword #:music) + #:init-keyword #:music #:asset? #t #:watch? #t) (background-music-volume #:accessor background-music-volume #:init-form 1.0 - #:init-keyword #:music-volume) + #:init-keyword #:music-volume #:watch? #t) (background-music-loop? #:accessor background-music-loop? #:init-form #t - #:init-keyword #:music-loop?)) + #:init-keyword #:music-loop? #:watch? #t)) + +(define-method (refresh-background-music (scene <scene>)) + (let ((source (background-music-source scene))) + (if (audio? (background-music scene)) + (begin + (set-source-volume! source (background-music-volume scene)) + (set-source-loop! source (background-music-loop? scene)) + (set-source-audio! source (background-music scene)) + (source-play source)) + (source-stop (background-music-source scene))))) + +(define-method (on-change (scene <scene>) slot-name old new) + (case slot-name + ((background-music background-music-volume background-music-loop?) + (refresh-background-music scene)) + (else + (next-method)))) (define-method (on-enter (scene <scene>)) - (when (audio? (background-music scene)) - (set-source-volume! (background-music-source scene) - (background-music-volume scene)) - (set-source-audio! (background-music-source scene) - (background-music scene)) - (source-play (background-music-source scene)))) + (refresh-background-music scene)) (define-method (on-exit (scene <scene>)) (source-stop (background-music-source scene))) |