I'm currently trying to make a game using SFML.
And my idea is, to make a function that ends a music smoothly by decresing its volume to zero before stopping it. As I write two functions that use while statement, I realized that I can't run the screen fade and music ending functions at the same time.
So I tried to use multithreading.
But when I wanted to do that, I got this error :
\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
My function code :
void endMusic(sf::Music &music){
sf::Clock clock;
sf::Time volumeDownInterval;
while(1){
if(music.getStatus()!=0){
if(volumeDownInterval>200){
music.setVolume(music.getVolume()-5);
clock.restart();
}
if(music.getVolume<=5)music.stop();
}
}
}
in my main function, I wrote :
int main(){
sf::Music music;
music.openFromFile("music/test.wav");
music.play;
music.setLoop(TRUE);
sf::Thread thread(&endMusic,music);
...
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
thread.launch();
fadeAnimation();
}
}
}
I've also read about Mutexes but I don't think there's an exception from the music function, as I tried it before and had the music to fade out first before the screen fades.
I have known SFML for only a week, so I'd be happy to hear out your opinions about my problem. Thank you.