From 2f1dff9659942f7ed7d9327d3c485ec872bbe2c6 Mon Sep 17 00:00:00 2001 From: Chris Pritchard Date: Mon, 6 May 2019 18:25:02 +1200 Subject: [PATCH] added a note about the sound system design --- samples/space-invaders-clone/readme.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/samples/space-invaders-clone/readme.md b/samples/space-invaders-clone/readme.md index 9cd44c1..4f305db 100644 --- a/samples/space-invaders-clone/readme.md +++ b/samples/space-invaders-clone/readme.md @@ -4,6 +4,14 @@ A partial recreation of the 1979 classic. In contrast to Tetris, there are many This sample also uses artwork, specifically a sprite sheet for the player and invader graphics. The invaders and projectiles are animated, so you can see a way that can be done with Xelmish. +## Sound System + +One of the interesting elements of this sample is how sounds are handled. A sound is played due to a specific event, which means in the Elmish model it best fits to be set in either the update function, or in the view function when an event is dispatched. However, the way 'view's work, is they are set and re-rendered on every view of the XNA loop until the model is changed; a sound played ondraw will therefore get played hundreds of times a second (on fast machines) - not ideal: you want the option to usually play a sound once. + +The solution is not built in to Xelmish, though a helper provides one option which is what is used in this sample: add a Queue to your model, and enqueue the keys of sounds to play. Then use a dequeue on each draw to play the next sound, ensuring each enqueued sound is played just once. + +While this is a mutable solution using a .NET collections class that feels a bit wonky to use from F# (compared to the rest of the nearly purely functional code), it does work perfectly. So if that solution works for you and you don't mind a slightly hybrid model type, then go for it! + ## Credits Space Invader sprites by [GooperBlooper22](https://www.deviantart.com/gooperblooper22), acquired from [here](https://www.deviantart.com/gooperblooper22/art/Space-Invaders-Sprite-Sheet-135338373). These have been provided under no specific license, but credit given anyway. @@ -12,4 +20,4 @@ The game itself, for mechanic reference, was played via the [Internet Archive](h The font used is "Press Start 2P" from [here](https://fontlibrary.org/en/font/press-start-2p). It is available under the SIL Open Font License, a copy of which is in the root of this solution. -The sounds are from user [Krial](https://opengameart.org/users/krial) on [OpenGameArt.Org](https://opengameart.org), specifically the [siclone sound effects pack](https://opengameart.org/content/siclone-sound-effects), under the [CCO 1.0 license](http://creativecommons.org/publicdomain/zero/1.0/). \ No newline at end of file +The sounds are from user [Krial](https://opengameart.org/users/krial) on [OpenGameArt.Org](https://opengameart.org), specifically the [siclone sound effects pack](https://opengameart.org/content/siclone-sound-effects), under the [CCO 1.0 license](http://creativecommons.org/publicdomain/zero/1.0/). I didn't use the sounds as they are named - e.g. I use menu for the 'beep' sound on shuffle. Just my preference. \ No newline at end of file