Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Playing the same sound over top of itself...  (Read 3112 times)

0 Members and 1 Guest are viewing this topic.

bglaze

  • Newbie
  • *
  • Posts: 46
    • View Profile
Playing the same sound over top of itself...
« on: November 02, 2011, 11:04:47 pm »
Okay, i could be missing something huge here, but I would like to be able to play the same sound over top of itself. For instance, when I shoot my lasers very fast in my game, I get buzzing sound if the sound hasn't finished playing. Then I tried using:

Code: [Select]
if(!lasersound.GetStatus())
    lasersound.Play();


However, this doesn't sound natural at all, because i have, say, 5 lasers in mid air, but I only heard one of them fire.

I understand (i think) that a new buffer must be created for each sound. But I am having a hard time conceptualizing how to do this. This must be a VERY common problem, because the need has arisen MANY times already in just my simple game.

Any ready solutions out there?
[/u]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Playing the same sound over top of itself...
« Reply #1 on: November 03, 2011, 07:59:42 am »
You must use the same buffer (no need to duplicate the audio data, it's always the same) but you have to create a new sf::Sound instance for every sound that you play.

Code: [Select]
sf::SoundBuffer buffer;
buffer.Load("sound.wav");

sf::Sound s1(buffer);
s1.Play();
sf::Sound s2(buffer);
s2.Play();
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Playing the same sound over top of itself...
« Reply #2 on: November 03, 2011, 08:02:15 am »
I think that this thread is already deprecated...
http://www.sfml-dev.org/forum/viewtopic.php?t=6210

Please don't duplicate threads about the same problem, or at least leave a message in the old one to inform people that your problem has evolved, and that there's a new thread for it.
Laurent Gomila - SFML developer