-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsoundHandler.hpp
More file actions
41 lines (31 loc) · 877 Bytes
/
soundHandler.hpp
File metadata and controls
41 lines (31 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef SOUNDHANDLER_HPP
#define SOUNDHANDLER_HPP
#include "SFML/Audio.hpp"
class SoundHandler{
public:
static void update() {
for (int i = playedSounds.size()-1; i >=0; i--) {
if (playedSounds[i]->getStatus() == sf::Sound::Stopped) {
delete playedSounds[i];
playedSounds.erase(playedSounds.begin()+i);
}
}
}
static void stop(sf::SoundBuffer& buffer) {
for (int i = playedSounds.size()-1; i >=0; i--) {
if (playedSounds[i]->getBuffer() == &buffer) {
playedSounds[i]->stop();
}
}
}
static void playSound(sf::SoundBuffer& buffer, float volume = 100, bool looped = false) {
sf::Sound* sound = new sf::Sound(buffer);
sound->setLoop(looped);
sound->play();
sound->setVolume(volume);
playedSounds.push_back(sound);
}
protected:
static std::vector<sf::Sound*> playedSounds;
};
#endif // SOUNDHANDLER_HPP