Skip to content

5. Looping Sounds with JSAM

Brogrammist edited this page Sep 22, 2020 · 3 revisions

This guide assumes that you have set up AudioManager and have generated it's Audio Library already. If you'd like to bring yourself up to speed, you can read up on Getting Started with JSAM and Playing Your Sounds

Looping your Sound

JSAM includes various features that help make looping your sounds and music easy!

JSAM allows you to loop your sound in a single line of code! With an AudioManager in your scene and a sound library regenerated, all you need is the PlaySoundLoop method. And just like with PlaySound, you can add a reference to a Transform as a second parameter to spatialize the looping sound.

But as with all loops, you'll need a way to leave them! So JSAM includes some companion methods to help as well.

IsSoundLooping and StopSoundLoop are PlaySoundLoop's best friends and will ensure that your game runs smoothly.

In the case that you passed a Transform component as a second parameter in PlaySoundLoop, you can also pass the same Transform into StopSoundLoop. This is useful in the case that you have two instances of the same sound looping at the same time and want to stop a specific one.

Clone this wiki locally