I just released another open source component, AudioHelper!
The AudioHelper class exists to allow you to have a single access point into the Cocos2d-x engine’s audio framework, with some neat optimisations in order to make adding audio simpler. The AudioHelper simply is a generic interface into the audio frameworks, with some extra icing on the top! It can also allow you to switch out your audio framework as and when you need to, without having to change any code within your main game, as the AudioHelper will be the only part of your project that will touch the audio framework itself!
Some great examples of why the AudioHelper is really helpful are (as copied from the GitHub description!):
Let’s say you have a background music track, and you can change the volume of the audio between 0% - 100%. You don’t want the music to be played if the volume is equal to 0, but you don’t want your code to be littered with calls to the audio framework checking the volume! Simply call
playBackgroundMusic()with the track of your choosing, and the AudioHelper will check the volume for you, and if it’s above 0 it’ll play the music!
You may also have different audio formats depending on the platform, but don’t want the code to handle choosing the format suffix littered around your fancy game code. Simply call
playEffect()with the effect of your choosing, and it will determine the correct format and play the effect (only if the effect volume is also above 0!)
You may also have adverts in your game, and want to disable the background music whenever they are shown and re-enable it when the advert disappears. AudioHelper carries this out of the box, call
advertStarted()when an advert is successfully presented to stop the music and
advertFinished()when it is dismissed. If the volume is above 0, the music is played again when the advert is dismissed!
You may decide one day to switch your current audio framework for another, but with your non-AudioHelper audio implementation you’ve got to change the framework references and implementations across your ENTIRE project. That sucks. With AudioHelper you’ve only got to change your references and implementation in one place, the AudioHelper. The functions provided to interface from your game to the AudioHelper are generic, allowing those to stay the same within your game while the audio framework gets switched out to another!
The AudioHelper class is incredibly easy to use, and when integrated will make game audio incredibly easy to manage!
Check it out here: https://github.com/ryanbourneuk/AudioHelper!
Have a great evening, if anyone has any questions please do let me know!