SFML community forums

Help => Audio => Topic started by: Astrof on March 05, 2009, 06:13:03 am

Title: sf::Sound SetPosition, how does it work?
Post by: Astrof on March 05, 2009, 06:13:03 am
I'm having trouble getting the SetPosition thing to work.  I'm thinking my problem is my z value, but I'm not exactly sure.  I define a position by doing a sound.setPosition(x,y,0), x and y being the position of the drawable at initialization.  I tried changing the 0 to a 1 or a -1 and it still didn't work (no sound was played).  what am I doing wrong? It's probably something real stupid...
Title: sf::Sound SetPosition, how does it work?
Post by: Laurent on March 05, 2009, 07:48:42 am
In 3D, Y is the "up" vector. I guess you want to use X and Z to map your 2D view.
Title: sf::Sound SetPosition, how does it work?
Post by: Astrof on March 05, 2009, 03:39:37 pm
oh makes sense, thanks!

This is the reason why I stick to 2D game programming...I'm directionally dyslexic.


EDIT: What do I have to set the Y value then to get it to work? It still doesn't play the sound when I do sound.SetPosition(x,value,y) where value is a number (I tried 0,1,-1,100,etc).
Title: sf::Sound SetPosition, how does it work?
Post by: Laurent on March 05, 2009, 03:53:05 pm
If you can show me a minimal and complete example that reproduces the problem, I'll try it myself.
Title: sf::Sound SetPosition, how does it work?
Post by: Astrof on March 05, 2009, 04:11:13 pm
I just do:
sound.SetPosition(x,value,y);
where value is a value that I experimented with and x and y are the initial position of the object on the screen.  

I did a quick test on a test program and it seems that only small values seem to work.  (It seems that If the x and y values go too far away they are just not heard).  

What units are a sound's position measured in? Because I think I'm using pixel positions to try to map them.  Also is 0,0 the Center of the screen (this could also be a problem with my current code)?
Title: sf::Sound SetPosition, how does it work?
Post by: Laurent on March 05, 2009, 04:24:34 pm
There's no absolute unit. The origin is given by position of the listener, and the "scale" is given by the attenuation. Just find the proper values for your application.
Title: sf::Sound SetPosition, how does it work?
Post by: Nexus on June 07, 2009, 04:57:24 pm
I found a very useful homepage where 2D sound spatialization with SFML (!) is explained. I thought I'd share it, in case one should come across this thread.

-> Link (http://blog.tbam.com.ar/2009/05/sound-spatiaiization-for-2d-games-in.html)
Title: sf::Sound SetPosition, how does it work?
Post by: Astrof on June 07, 2009, 09:32:20 pm
Wow that article is really helpful, thanks!
Title: sf::Sound SetPosition, how does it work?
Post by: nitram_cero on June 08, 2009, 06:42:57 pm
Yey! I wrote that :D
I'm glad it helped!

You might encounter some degree of engrishness  :P
Title: sf::Sound SetPosition, how does it work?
Post by: Nexus on June 08, 2009, 08:52:10 pm
Quote from: "nitram_cero"
Yey! I wrote that :D
I'm glad it helped!
Ah, I didn't know that. Very nice work, thanks a lot. :)