Salad Solutions is a compilation of educational resources developed by the GameSalad team. Resources include: webinar videos, Question of the Week answers, and Cookbook highlights.
In today’s Question of the Week, Billy Garretsen of GameTeamOne explores the most commonly received questions (via the forums and customer support) surrounding the use of sound optimization methods when combating sound latency device issues. He provides a set of best practices that can be applied to all platforms in order to improve sound performance.
Question of the Week: Sound Solutions
Many of our users have experienced sound latency issues from time to time, mostly apparent when playing games on Android devices. Check out http://forums.gamesalad.com/discussion/37166 for some background as to why GameSalad made the choice to support Nook and Kindle which use a modified version of Android’s OS notorious for sound delay.
While this post is aimed to alleviate some of the Android concerns, the practices we go over can apply to all platforms for varying degrees of sound performance gains. Please note, the following techniques are merely suggestions – not absolutes. Every game is different and it really boils down to what makes sense for your situation.
For reference when we refer to “sounds” we literally mean sound effects, or more specifically sound that is not music.
TECHNIQUE 1: “First In Line Behavior”
This technique is an easy method to try first when experiencing sound delay. Since GameSalad processes behaviors in the order they appear in the logic stack you can start processing sound before anything else if the Play Sound behavior exists first in the order of operations. If you have really dense rules then this is a great way begin your optimization pass. This solution, though, is only a starting point. If you still experience delays then you may need to do a little more work to address the problem.
PROS: Easy to try and test.
CONS: Potential for significant performance gains are low.
TECHNIQUE 2: “Sound Manager Actor”
The core concept of this technique is to localize all of your major sound behaviors into one actor in each scene. This actor is known as a sound manager. Basically, what a sound manager does is watch what is going on in any given scene and when an event happens it knows to play the corresponding sound.
The way a lot of folks implement sound is directly into the actor that makes sense. If an actor runs or jumps or gets hit, all of those sound behaviors are typically placed inside that character actor. The thing is, player characters usually have the most complicated logic compared to other on screen elements. What this can lead to is poor code optimization and sound behaviors getting buried in the mix.
Most major sounds in your game can probably be triggered by a game attribute. For example, If you have a game with touch screen controls, or even invisible touch triggers for character actions, then you probably have game level attributes for each major action. For example, a jump button may trigger a BOOLEAN game attribute, “game.jump”, to true when pressed. Then your character has logic in it to change its Linear Y Velocity to 500 when game.jump is true, resulting in the character leaping. This is also traditionally where a jump sound behavior may be located.
The alternative would be to have a single sound manager actor somewhere in your scene, most times hidden off camera, that is looking at those game attributes and only directing sounds to play. So rather than the character triggering the Play Sound Behavior when game.jump is true, this sound manager actor would play the sound when game.jump was true. The benefit here is the sound manager actor will only have to process one sound call and no other complicated logic at the time the game attribute changes.
This does not only apply to player characters – you can apply this technique to any and all sound effects that can be triggered off of game attributes, including enemies, environmental effects, and UI sounds.
PROS: Organizes sound management in one central location; high potential for performance gain.
CONS:Time consuming to set up for some larger projects with lots of sound effects.
NOT RECOMMENDED TECHNIQUE 3: “Sound for Music”
Many users have already discovered a phenomena where Play Music behaviors tend to trigger and process faster than the Play Sound behaviors. What some folks have done is reformatted their sound effects into music assets (mp3 or m4a) and trigger Play Music behaviors anywhere sounds would have normally gone. While we cannot prevent the use of this technique it is preferred that you try other optimizations. The biggest sacrifice you will notice is the inability to play sounds and music at the same time, since GameSalad currently only allows for one music track playing at any given time. This means if your game requires multiple layers of audio to get the full experience you will short change yourself and players. Use at your discretion.
PROS: proven method for rapid sound effect processing on Android devices.
CONS: does not allow multiple audio tracks at same time – can give the presentation a choppy feel.
TECHNIQUE 4: “Scrub Your Logic”
If none of the techniques described help to improve sound performance in your app, then there may be deeper issues with your logic optimization preventing smooth playback. It would be a good practice to always do a few scrubs of your actors and eliminate unnecessary behaviors or recreate convoluted logic stacks with fewer/condensed behaviors. It takes a lot of patience and discipline but all developers have to redo work from time to time in order to pump out every ounce of performance possible.
Some potential areas of performance dip include:
– Scenes with lots of high resolution art
– Scenes with animations or images that are being referenced in code but not used at run time
– Actors that have multiple constrain attributes at the game level
– Large scenes with wrap on X or Y and many actors that cycle around
– Actors with many separate rules that reference the same attributes
– Timers with short update cycles that contain constraints or long logic strings
PROS: Will undoubtedly improve game performance in every aspect.
CONS: Can be frustrating and time consuming.
Remember, there are many approaches to solving this problem with sound performance and the key takeaway is to find what works for you and stick with it.
We hope this helps give some of you ideas for your current and future projects.
– Billy Garretsen, GameTeamOne