Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fratello Manu on Wed 14/07/2021 08:24:26

Title: Edit views frames sound
Post by: fratello Manu on Wed 14/07/2021 08:24:26
Hi everyone!

Is it possbile to assign at run-time a sound to a specific frame of a loop of a view?

Basically, in a game with many characters, all of them with many frames for walking animations, I'd like to assign the footstep sound using a loop, instead of entering every single frame of every character view:

for [every view]
{
    if [View is a walking animation / I'll check with a specific name prefix....]
    {
        for [every loop of the view]
        {
            loop.frame[3].sound = step.ogg
            loop.frame[5].sound = step.ogg
            loop.frame[7].sound = step.ogg
        }
    }
}


Any idea?
thanks!
Manu
Title: Re: Edit views frames sound
Post by: Khris on Wed 14/07/2021 08:50:23
This is possible pretty much exactly like you imagine, now all you need is the proper commands from the manual.
To change a single sound you need a ViewFrame. You can get one using

static ViewFrame* Game.GetViewFrame(int view, int loop, int frame)

The number of views, loops and frames can be read using  Game.ViewCountGame.GetLoopCountForView  and  Game.GetFrameCountForLoop

(note that the view index is 1-based)

Once you have a ViewFrame, you can change it's  .LinkedAudio
Title: Re: Edit views frames sound
Post by: fratello Manu on Wed 14/07/2021 09:20:46
Thanks a lot!
Title: Re: Edit views frames sound
Post by: fratello Manu on Mon 02/08/2021 15:28:34
Hi everyone.
I've got a problem on this.

I implemented the algorithm and everything was fine.
Something like:


Code (ags) Select

void SetStepSoundForView(int viewNumber)
{

  int loopCount = Game.GetLoopCountForView(viewNumber);
 
  for (int loopIndex = 0; loopCount - 1; loopIndex++)
  {
    int frameCount = Game.GetFrameCountForLoop(viewNumber, loopIndex);

    ViewFrame* frame;
   
    switch(loopIndex)
    {

      // Down, Up: 3, 7

      case 0:
      case 3:
        frame = Game.GetViewFrame(viewNumber, loopIndex, 3);
        frame.LinkedAudio = aStep;
        frame = Game.GetViewFrame(viewNumber, loopIndex, 7);
        frame.LinkedAudio = aStep;       
        break;
     
      // Left, Right: 1, 5

      case 1:
      case 2:
        frame = Game.GetViewFrame(viewNumber, loopIndex, 1);
        frame.LinkedAudio = aStep;
        frame = Game.GetViewFrame(viewNumber, loopIndex, 5);
        frame.LinkedAudio = aStep;         
        break;
     
    }
  } 
}



...so, I pass a view to this function and depending on direction (case 0, case 3, case 1, case 2)  I want to assign the step sound to the desired frames (3 and 7 for walking up/down, 1 and 5 for walking left/right)

The walking views just contain 4 loops.

As I wrote, it was working, but suddenly I got this error: "invalid loop specified", on statement

Code (ags) Select
int frameCount = Game.GetFrameCountForLoop(viewNumber, loopIndex);

I think the only thing I changed was uninstalling AGS 3.5.0 and installing AGS 3.5.1 (Build 3.5.1.8)

May it be possible?

Thanks!
Have a nice day
Manu
Title: Re: Edit views frames sound
Post by: Khris on Mon 02/08/2021 15:39:17
Code (ags) Select
  for (int loopIndex = 0; loopCount - 1; loopIndex++)

needs to be

Code (ags) Select
  for (int loopIndex = 0; loopIndex < loopCount; loopIndex++)