YAPOG  0.0.1
Yet Another Pokemon Online Game
AudioManager.cpp
Go to the documentation of this file.
5 
6 namespace yap
7 {
9  : currentMusic_ (nullptr)
10  , previousMusic_ (nullptr)
11  , currentSound_ (new sf::Sound ())
12  {
13  }
14 
16  {
17  }
18 
20  {
21  static AudioManager instance_;
22 
23  return instance_;
24  }
25 
26  void AudioManager::PlayMusic (const String& musicName, bool fromBegin)
27  {
28  if (currentMusic_ != nullptr)
29  {
30  currentMusic_->pause ();
32  }
33 
34  currentMusic_ = &ContentManager::Instance ().LoadMusic (musicName);
35 
36  currentMusic_->setLoop (true);
37 
38  if (fromBegin)
39  currentMusic_->stop ();
40 
41  currentMusic_->play ();
42  }
43 
44  void AudioManager::PlaySound (const String& soundName)
45  {
46  if (currentSound_ != nullptr)
47  currentSound_->stop ();
48 
49  currentSound_->setBuffer (
50  ContentManager::Instance ().LoadSoundBuffer (soundName));
51 
52  currentSound_->play ();
53  }
54 
56  {
57  if (previousMusic_ != nullptr)
58  {
59  void* tmp = currentMusic_;
60 
61  currentMusic_->pause ();
62  previousMusic_->play ();
64  previousMusic_ = (sf::Music*)tmp;
65  }
66  }
67 
68 } // namespace yap