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

Author Topic: Playing sounds simultaneously  (Read 2708 times)

0 Members and 1 Guest are viewing this topic.

seba174

  • Guest
Playing sounds simultaneously
« on: September 21, 2017, 09:43:57 pm »
Hi,
i have a problem when trying to play few sounds simultaneously.

I am currently using this method:
SoundManager.h
(click to show/hide)

SoundManager.cpp
(click to show/hide)

When i use playSound() function after Player does specific action, it plays sound properly. But the problem is, that when i use playSound() and then after a short time (when the sound hasn't finished yet) use it again, the new sound of course starts, but that one which hasn't finished yet can't be heard (it just stops).
Is there any method to solve this?

Thanks in advance for all replies.
seba174

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Playing sounds simultaneously
« Reply #1 on: September 21, 2017, 10:22:12 pm »
It could be the vector resizing as that would cause it to have to move the elements to a place that would fit them all. When an sf::Sound is moved, it is stopped.

A couple of solutions to this are: 'pre-size' the vector to a size that would cover however many sounds might be playing at once (pre-size here means to resize or reserve the vector), or use an std::list or std::forward_list instead of a vector.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

seba174

  • Guest
Re: Playing sounds simultaneously
« Reply #2 on: September 21, 2017, 10:39:37 pm »
Yeah, you are right. I changed std::vector for std::list, and that did the trick. Now everything works as intended.
Thanks a lot for help.
Regards,
Sebastian