I'm trying to make an rpg style game for an AP class, but I have run into an issue with trying to stop different sounds when entering a new area. Is there any way to terminate the sounds from other methods?
I've tried working with ASYNC, but it doesn't play the sounds at all (this may be due to multithreading/methods running concurrently), along with SND_FILENAME | ASYNC. I'm not too familiar with the concepts I'm using, and any guidance will go a long way.
The three sound methods:
void menu()
{
while(startMusic==1)
{
PlaySound(TEXT("C:/finalprojectmusic/passaway.wav"), NULL, SND_FILENAME);
}
}
void landscape()
{
while(starter==1)
{
PlaySound(TEXT("C:/finalprojectmusic/oddish.wav"), NULL, SND_FILENAME);
}
}
void battle()
{
while(battleOn==1)
{
PlaySound(TEXT("C:/finalprojectmusic/finboss.wav"), NULL, SND_FILENAME);
}
}
When I run the file normally, the differing sounds in each method enter in as soon as the previous stops while going into a new area, which is alright, but not desired.
I found out how to solve the problem, if anyone is having a similar problem, here's what I did:
void menu()
{
while(startMusic==1)
{
PlaySound(TEXT("C:/finalprojectmusic/passaway.wav"), NULL, SND_FILENAME|SND_ASYNC);
for(int i=0; i<=passawayLength;i++)
{
if(starter==1)
{
return;
}
_sleep(1000);
}
}
}
void landscape()
{
while(starter==1)
{
PlaySound(TEXT("C:/finalprojectmusic/oddish.wav"), NULL, SND_FILENAME|SND_ASYNC);
for(int i=0; i<=oddishLength;i++)
{
if(battleOn==1)
{
return;
}
_sleep(1000);
}
}
}
void battle()
{
while(battleOn==1)
{
PlaySound(TEXT("C:/finalprojectmusic/finboss.wav"), NULL, SND_FILENAME|SND_ASYNC);
for(int i=0; i<=finbossLength;i++)
{
_sleep(1000);
}
}
}
I just needed it to wait til the end ^^