I am trying to program a game. To keep it short, the object of the game is to bet on one of 4 dogs, hit start race, the dogs run, and if your dog finishes first you win. The problem I'm having is with the audio. I have audio playing in the background the whole time, and when you hit start race, the code will stop the background audio, play an audio clip of a gun firing, and then the dogs run. The problem comes right after the audio clip of the gun firing finishes up. As soon as it does, the dogs start running slower across the screen, like the program is lagging. I know it has something to do with the audio, and specifically with the fact that the audio just finished playing because if i remove all audio, it runs fine. If audio plays the whole time the dogs run, it is fine. Any ideas? I can post the code if needed. Thanks.
Loading
Jonathan CoxPosted Nov 7, 2009, 8:52 AM
private void button3_Click(object sender, EventArgs e)
{
//This is the start race button. When clicked it disables the background music
//and plays the audio clip to start the race. It has all the controls to run the race
//and decide the winner. Also contains controls for the payout if the winning dog was
//bet on. It then resets the race and all options and buttons so the next race can be
//ready to begin.
Jon.MoneyonTable -= (int)numericUpDown1.Value;
Jon.Bank = Jon.MoneyonTable + Jon.Cash;
label2.Text = "You have $" + Jon.MoneyonTable +" at the table.";
label4.Text = "Your total money is " + Jon.Bank + ".";
sp.Stop();
if (MuteMusic.Checked != true)
{
gun.Play();
}
checkBox2.Enabled = false;
checkBox3.Enabled = false;
buttonStartRace.Enabled = false;
System.Threading.Thread.Sleep(500);
while (Greyhound1.Location < Greyhound1.RaceTrackLength || Greyhound2.Location < Greyhound2.RaceTrackLength
|| Greyhound3.Location < Greyhound3.RaceTrackLength || Greyhound4.Location < Greyhound4.RaceTrackLength)
{
if (Greyhound1.Location < Greyhound1.RaceTrackLength)
{
Greyhound1.Run();
}
......... this is just the beginning part of what the button does, but i think it should be all you need, I don't know, its my first program lol.
Jorge L FernandezPosted Nov 6, 2009, 12:13 AM
It looks like your code flow somehow remains doing something else right after finishing the Gun Fire clip and therefore the painting code get slow. Try disposing or releasing every resource related to that clip and would be very usefull if you put your code here to see more specific details.