Two sounds playing simultaneously?

Started by LeChuck, Fri 07/10/2005 09:55:38

Previous topic - Next topic

LeChuck

I have a screen where a train passes by every now and then. Here's the repeatedly execute script:

Quote
if ((character[TRAIN].x > -100) && (character[TRAIN].x < 420)) { // If train is closing in on visible screen, play the train sound
PlaySound(4);
}

if (character[TRAIN].walking == 0) { // When the train has reached its destination, it's time to go back
Ã,  int randomPosX = Random(1000)-2000; // Find random negative X value
Ã,  MoveCharacterPath (TRAIN, randomPosX, 152);
Ã, 
Ã,  int randomNegX = Random(1000)+2000; // Find random positive X value
Ã,  MoveCharacterPath (TRAIN, randomNegX, 152);
Ã,  }

if (AreCharactersColliding(EGO, TRAIN)) { // Character being hit by train
Ã,  Display("Ouch!");
Ã,  }

if (AreCharObjColliding(TRAIN, 0)) { // Train hits bottle
Ã,  ObjectOff(0); // Bottle vanishes
Ã,  ObjectOn(1); // Insides revealed
   }

I have this puzzle where, in order to open a bottle, you have to put in on the train tracks and wait for the train to pass by. As the train is already making a sound when it's passing by, having the engine output a nice glass breaking sound proved harder than I imagined.

Putting a "PlaySound(X) while (IsSoundPlaying()) Wait(1);" in the AreCharObjColliding part won't work, since there is a sound playing continously from before (the train sound). A simple PlaySound(X) obviously won't work as it's in the rep execute script. I've tried experimenting with various Global Ints also, but haven't had any luck here.


In short, my questions are:

A) How do I workaround this problem?
B) How come the AGS engine can't find out whether a spesific sound effect is playing or not? Why not a IsSoundPlaying(X) function?

Ashen

#1
A)
Consult the great and mystic oracle known as 'The Manual':PlaySoundEx
Basically, play the train sound in one channel, and the glass sound in another, and it should work. (This way, you can also use IsChannelPlaying() in the while loop.) Alternatively, if you don't have an Ambient sound playing, you could use that for the train.

B)
I don't know, but I suppose it could be useful. Maybe you could suggest it, if it's not already on the tracker. In the meantime, if you really need it (or just want it), it's probably be easy enough to code your own workaround.
I know what you're thinking ... Don't think that.

LeChuck

Silly me, since PlaySoundEx always mentions "channels", I assumed left/right stereo channel and quickly disregarded the feature. Thanks Ashen!

SMF spam blocked by CleanTalk