Im trying to work with 2d sounds, for It I have this code:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
int main()
{
sf::RenderWindow App(sf::VideoMode(600, 600), "My window");
sf::Texture t;
t.loadFromFile("Speaker.png");
sf::Sprite speaker(t);
speaker.setRotation(90);
speaker.setOrigin( t.getSize().x / 2.0f, t.getSize().x / 2.0f );
speaker.setPosition(300, 300);
sf::Text text("Song: Reunited by Incomptech.com", sf::Font::getDefaultFont(),14);
text.setPosition(5,5);
text.setColor(sf::Color::Black);
sf::Listener::setDirection(0, -1, 0);
sf::Listener::setPosition(0, 0, 0);
sf::Music music;
music.openFromFile("Reunited.ogg");
music.setLoop(true);
music.setPosition(300,300,0);
music.setMinDistance(5.f);
music.setAttenuation(10.f);
music.play();
while (App.isOpen())
{
sf::Event event;
while (App.pollEvent(event))
{
if (event.type == sf::Event::Closed)
App.close();
}
sf::Vector2f pos; //relative to center of the screen
pos.x = sf::Mouse::getPosition(App).x - 300;
pos.y = sf::Mouse::getPosition(App).y - 300;
sf::Listener::setPosition(pos.x, pos.y, 0);
App.clear(sf::Color::White);
App.draw(text);
App.draw(speaker);
App.display();
}
return 0;
}
But when I move the mouse the volume stays at 1, it wont change at all