CLI How to play multiple SoundPlayers at the same time?
Jun 2, 2015 at 8:07pm UTC
Hello,
I am trying to make a game, but I have having trouble trying to get more than one sound to play at the same time (in my example, this would be Main playing while Gunshot is playing).
Here is the code that I am trying to get to work:
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 42 43 44 45 46 47 48 49 50 51
char dir;
static SoundPlayer^ Gunshot=gcnew SoundPlayer("C:\\Users\\Owner.Ben-PC\\Desktop\\eclipse\\workspace\\Galaga\\bin\\BossGunSound.wav" );
static SoundPlayer^ Main=gcnew SoundPlayer("C:\\Users\\Owner.Ben-PC\\Documents\\Visual Studio 2010\\Projects\\SuperMetroidCraft\\Resources\\MainTrack.wav" );
...
...
...
#pragma endregion
private : System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
Main->PlayLooping();
}
private : System::Void GunTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
Gunshot->Play();
}
private : System::Void PlayerMoveTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
if (dir=='r' )
{
this ->Player->Left+=10;
}
}
private : System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if (GunTimer->Enabled==false &&e->KeyCode==Keys::E)
{
GunTimer->Enabled=true ;
}
if (PlayerMoveTimer->Enabled==false &&e->KeyCode==Keys::Right)
{
dir='r' ;
PlayerMoveTimer->Enabled=true ;
this ->Player->ImageLocation=("C:\\Users\\Owner.Ben-PC\\Documents\\Visual Studio 2010\\Projects\\SuperMetroidCraft\\Resources\\PlayerRunLeft.gif" );
}
}
private : System::Void Form1_KeyUp(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if (GunTimer->Enabled==true &&e->KeyCode==Keys::E)
{
GunTimer->Enabled=false ;
}
if (PlayerMoveTimer->Enabled==true &&e->KeyCode==Keys::Right)
{
PlayerMoveTimer->Enabled=false ;
this ->Player->ImageLocation=("C:\\Users\\Owner.Ben-PC\\Documents\\Visual Studio 2010\\Projects\\SuperMetroidCraft\\Resources\\PlayerStandLeft.jpg" );
}
}
};
}
Last edited on Jun 2, 2015 at 8:07pm UTC
Topic archived. No new replies allowed.