I would like to be able to create a map object that plays audio once (i.e. not looping) each time a player comes within range, is there a way to do this?
Currently if I set sound.loop = false, the audio is only played once for the ‘browser session’, for any given player, rather than playing it once each time the player come into range of the object.
Is it possible to do this?
not tried it myself yet, but in the API there is “loop”: true bit, so assume one could change that to false.
Yes, you can do that. The problem is when loop == false the audio is only played once for that player for the ‘browser session’. i.e. if the player moves away from the object and then goes back it won’t play the audio. What I want to achieve is that each time the player comes within range of the object the associated audio is played, but not in a loop.
what would happen if you had the audio clip, with a long silence on the end? then left it on loop. would it “restart” when coming close again? that way the big silence would be an indicator to ‘move on’, but at least it would trigger again when close. I’ve not tested this myself, but would like to know the result if you do it!
If you want the museum effect, of motion sensing audio, you could:
-Subscribe to playerMove,
-Check to see if a player has moved into the range you want the audio to play at (I think 30 is default, but that is pretty large)
-When they move into range, set the ‘src’ of the emitter to the audio URL you want to use.
-When all players have left the area around the emitter, set the ‘src’ to blank (’’).
This is the only way I have found to do this, that doesn’t try to abuse creating new rooms. Note that the first player in will start the audio, and the last player out will end it. It will also play simultaneously for all within range, not individually.
Thanks for that, I will do some experimenting!
Hi Mel! I saw this post pop up in my feed, this is before I started managing the forum so I missed it, but we’ve added a
game.playArbitrarySound function that lets you send sounds to people! You can just pass in a
targetId with the person you want to play it for, and it will play it on their client.
Happy hacking & holidays,
@opalrose Thanks for that, I’ll give it a go.