1
I am programming a game for school work in C++, and I have a game that during its execution starts a song, then when I click on the space key to fire the music stops and only hear the shot of the gun.
I wish I could play both the background music and the game music.
Here is my code:
private: System::Void GameForm_Load(System::Object^ sender, System::EventArgs^ e)
{
PlaySound(TEXT("../Musicas/Game.wav"), NULL, SND_ASYNC | SND_LOOP);
}
This song starts when I open the page. And this when I click in space:
private: System::Void GameForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
switch (e->KeyCode)
{
case Keys::A:
Nave->Left -= 20;
break;
case Keys::D:
Nave->Left += 20;
break;
case Keys::W:
Nave->Top -= 20;
break;
case Keys::S:
Nave->Top += 20;
break;
case Keys::Space://Carrego no espaço e o som e executado
PlaySound(TEXT("../Musicas/Laser.wav"), NULL, SND_ASYNC);
break;
}
}
The background music for when I run the space. I wanted both songs at the same time.
I tried that option and it didn’t work
– kingwarrior05
@kingwarrior05 Have tried so
PlaySound(..., NULL, SND_ASYNC | SND_NOSTOP)
?– stderr
yes I have tried, when I replace I am unable to hear the shots
– kingwarrior05
@kingwarrior05 Searching deeper, it seems that the
PlaySound
does not support multiple sounds at the same time. (See this discussion). You may need to use a more sophisticated API like Directsound or Openal, or else the Xaudio2. :/– stderr