Asteroids Plus 2.0 - Milestone 16 - Audio


This is going to be a shorter post.  I’ve gotten to the point on the punch list where I had to address the sounds and audio of the game.  I have all the same audio files as last time I made this game, and I still like them. 

I historically use Howler.js for all my game dev audio stuff, and I see no reason not to continue to use it.  I created two new classes, one for background music and one for sound effects.  

The BGM class for this game is SUPER straightforward as I’m not switching BGM tracks in game like I do for Demon Siege.  It has one method…  .play(), and I call that when the user leaves the menu screen, which is nice, because the web technologies don’t let you start playing audio autonomously anymore, it requires some user interaction to enable.

The SFX class is not much more difficult, it let’s me import all the mp3 files I’m using for audio, then maps them to a keyword.



This class also has a play method that take that string keyword, for example, ‘playfire’ passed to it and it will play the ‘this.pFire’ Howl that’s pre-setup. Easy peasy…


The last bit of business for the audio, is to find the appropriate places in the code to fire off the sound effects, and the ECS system makes this super simple in my opinion.

I just asked myself, where do I need to play the sound for firing the weapon?  Well, that’s in the Player ECS class and in the fire method…. I just call SFX.play(‘playfire’); and it just works.  I went through all the audio files and placed them appropriately.  Asteroid collisions specifically have a nice method call, in my opinion, because I randomize the call to three different sounds when an asteroid collides.


How cool is that…

This currently hosted game site: https://mookie4242.itch.io/asteroids-plus-20

Twitter: @jyoung424242

SlideShare: https://www.slideshare.net/JustinYoung3/next-gen-asteroids

GitHub: https://t.co/utxHxXKdOz

Leave a comment

Log in with itch.io to leave a comment.