Hello there, beloved master devs and lovely coding beginners!
I was here messing around with SOUND functions and found out that a bit of sound panning may turn an otherwise boring experience into a fascinating headphone trip.
The problem I was experiencing was to produce the sound in the exat 2d coordinates of the event to produce a stereophonic effect.
And then I've come into this:
px = // the x position of a sprite or collision
unit# = 20000 / screen width()
pan_value = (px*unit#)-10000
SET SOUND PAN soundnumber,pan_value
And then the sound was played exactly where it was supposed to be in 2D space, correctly alligned with my speakers.
Incredible, huh? With just that piece of code you can play a sound correctly panned!
I know it is pretty silly, but I took long before finding out the most efficient way to position sounds, and finding out this little workaround made it possible to me to produce more engaging experiences with my little projects.
Hope you all find it useful!