Two questions about coding with music

Started by Fedx, Thu 14/01/2016 21:26:12

Previous topic - Next topic

Fedx

Hi guys! I need help with two things for my game.

The first one may be simple but I can't get it to work. There's a part where my character is stuck on the ceiling and needs to use his tongue to get some stuff from the floor to make a suit. There's some "tense" music that I made, which has 7 instruments (One for each part of the suit) and I want to add an instrument everytime you manage to get an item. Of course, I can't call up the function right away because there's going to be a rythmic gap between all the tracks. This is the code that I have in my room

Code: ags

// room script file

function oWrench_Interact(){
if (cGuard.Loop == 1)
{
  //Draw a "tongue" that sticks out of the character
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  DrawingSurface *backup = surface.CreateCopy();
  surface.DrawingColor = 224;
  surface.DrawLine(165, 54, 263, 153, 2);
  Wait(60);
  surface.DrawSurface(backup);
  backup.Release();
  surface.Release();
  oWrench.Visible = false;
}
else
  {
    //If he sees you, he takes all your stuff
    Display("The guard saw you!");
    oWrench.Visible = true;
    oCloth.Visible = true;
  }
}


function repeatedly_execute_always()
{
  if (!cGuard.Moving)
  {
    if (cGuard.x < 100)
    {
      // if the guard is on the left hand side of the screen,
      // start it moving towards the right
      cGuard.Walk(156, cGuard.y, eNoBlock, eAnywhere);
    }
    else
    {
      // if not, move it towards the left
      cGuard.Walk(15, cGuard.y, eNoBlock, eAnywhere);
    }
  }
}


function oCloth_Interact(){
if (cGuard.Loop == 1)
{
  DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  DrawingSurface *backup = surface.CreateCopy();
  surface.DrawingColor = 14;
  surface.DrawLine(165, 54, 278, 184, 2);
  Wait(60);
  surface.DrawSurface(backup);
  backup.Release();
  surface.Release();
  oCup.Visible = false;
}
else
  {
    Display("The guard saw you!");
    oWrench.Visible = true;
    oCloth.Visible = true;
  }
}


function room_FirstLoad()
{
  aTense_DrumSynth1.Play(eAudioPriorityHigh, eRepeat);
}


What I thought is that I could start playing all at the same time and then raise the volume everytime you got an item, but if I call this function only the first piece plays

Code: ags

function room_FirstLoad()
{
  aTense_DrumSynth1.Play(eAudioPriorityHigh, eRepeat);
  aTense_Drum2.Play(eAudioPriorityHigh, eRepeat);
  aTense_Violin.Play(eAudioPriorityHigh, eRepeat);
  etc...
}


Is there something missing?

The second one may be more difficult, and it's not that necessary, so if it's too much trouble, I don't mind taking it out. There's an arcade room with three machines and a booth, like this (Not the real image, just a mockup) . I have three tracks with music and noise for each machine, and I want that when you are near a machine y coordinate, the volume of that machine gets higher (The red lines on the image), and as you go inbetween them, the tracks for the two machines mix together.

My english is not that good so if there is something that I didn't explain right tell me and I'll try to clear it up. Thanks a lot!
- The gamer doesn't dies... he respawns -

MiteWiseacreLives!

I'm not an expert coder, but you might want to try assigning each track to a different channel, this should give you full control over volumes and I believe there are plenty of audio channels for what you're doing.

Snarky

#2
AGS has 8 channels total, meaning you can play 8 different sound clips at the same time. However, they are split into different AudioTypes (Music and Sound by default), with a MaxChannels for each. And the default MaxChannels setting for Music is 1, because the assumption is that you want to be able to play lots of different sounds at the same time, but only one music track. So if you try to play two different clips that both have AudioType Music, only one will actually play.

So to fix this, either change the MaxChannels value for the Music AudioType (but this will reduce the number of regular sounds you can play elsewhere), or change the audio type of these tracks to Sound.

I'd be a bit worried about the seven tracks actually playing correctly in sync, though. Audio can have a tendency to drift slightly, and it's very noticeable when it's not in perfect sync.

For your second question, you can use AudioChannel.SetRoomLocation(). It's also possible to script the effect yourself by manipulating the volume of the audio channels in repeatedly_execute() depending on the player's x position.

Fedx

Quote from: Snarky on Fri 15/01/2016 08:20:08
AGS has 8 channels total, meaning you can play 8 different sound clips at the same time. However, they are split into different AudioTypes (Music and Sound by default), with a MaxChannels for each. And the default MaxChannels setting for Music is 1, because the assumption is that you want to be able to play lots of different sounds at the same time, but only one music track. So if you try to play two different clips that both have AudioType Music, only one will actually play. I'd be a bit worried about the seven tracks actually playing correctly in sync, though. Audio can have a tendency to drift slightly, and it's very noticeable when it's not in perfect sync.

Oh wow, I never saw that the music options were there! Well, I'll see how I'll handle all of the tracks then, and check in different computers if audio syncs. Hope it works!

Quote from: Snarky on Fri 15/01/2016 08:20:08
For your second question, you can use AudioChannel.SetRoomLocation(). It's also possible to script the effect yourself by manipulating the volume of the audio channels in repeatedly_execute() depending on the player's x position.

Unfortunately, I have a repeatedly_execute and a repeatedly_execute_always, so I won't be able to do it. Thanks a lot for your answers anyways!!
- The gamer doesn't dies... he respawns -

Snarky

Quote from: Fedx on Fri 15/01/2016 22:15:49
Unfortunately, I have a repeatedly_execute and a repeatedly_execute_always, so I won't be able to do it.

That doesn't really make sense. You know you can do more than one thing in a function, right? And anyway, just use AudioChannel.SetRoomLocation().

SMF spam blocked by CleanTalk