Play sound on a particular background (solved)

Started by Dark Link, Sun 13/12/2009 16:38:13

Previous topic - Next topic

Dark Link

Hi all,

I've got an animated background of a drip falling from the roof and i want to play a sound on the final frame of the animation.

Is it possible to do this?

I've tried doing it manually with the Wait function but I can't get the timings right.

Thanks
"That's not a novel, it's the scribblings of a retard"

Khris

Use a timer and GetBackgroundFrame in the room's rep_ex. (Set the timer to a low number after playing the sound and only play it again if the timer is expired to prevent the sound from playing multiple times at once.)

DoorKnobHandle

If you don't want to use a timer, you can achieve the same with a simple boolean variable:

Code: ags

bool sound_played;

function repeatedly_execute ( )
{
      if ( GetBackgroundFrame ( ) == 3 )
      {
            if ( !sound_played )
            // if the sound hasn't played yet
            {
                  // play your drip sound
                  PlaySound ( ... );
                  
                  sound_played = true;
            }
      }
      else if ( GetBackgroundFrame ( ) == 3 - 1 )
      // the frame right before the sound frame
      {
            sound_played = false;
      }
}


Replace the '3's with your frame number for the sound, obviously.

I didn't check this, it's all from the top of my head. I'm pretty sure the method works, there might be typos in there however. You'll also need to look up the parameters for the PlaySound command or use the new functionality to play your sound in the new version of AGS, I'm sure you already know how to do this.

EDIT: BTW, depending on your game, it might be way better to use an object with an animated view for the drip (performance wise and it'll make adding the sound trivial, just do it via the frame-sound functionality in the view editor).

Dark Link

"That's not a novel, it's the scribblings of a retard"

SMF spam blocked by CleanTalk