Sound linked to a frame / SetRoomLocation problem

Started by rongel, Wed 17/10/2018 15:31:31

Previous topic - Next topic

rongel

An audio related question (names and situations have been changed to avoid spoilers!):

Let's say that I have a blacksmith smithing with a hammer in a long, scrolling room . I want that:

1. The hitting sound plays precisely at the moment of impact (I can do this with the Linked audio property, or in the View editor).
2. That the sound volume increases as player approaches the blacksmith, and decreases when player walks away (I can do this with SetRoomLocation-command, and give the sound X and Y room coordinates).

The problem is that I can't seem to combine these two methods. I've spent hours trying to make the animation and the sound match each other, but the sound always starts to drift and lose the sync, which is no good. And it seems impossible to use Linked audio property with an audio channel.

My script is basically something like this, it works except the sync is off:

Code: ags

cBlacksmith.Lockview(HIT_HAMMER);
cBlacksmith.Animate(1, 2, eRepeat, eNoBlock); 

AudioChannel Hammer_impact = aHammer_impact.Play(eAudioPriorityNormal, eRepeat);
Hammer_impact.SetRoomLocation (800, 180);


So is there a third way to do this, or is this impossible?

Any help is appreciated, I'm so close getting this thing working!
Dreams in the Witch House on Steam & GOG

Khris

Instead of using eRepeat, use repeatedly_execute:

Code: ags
  if (cBlackSmith.Frame == 4) {
    AudioChannel Hammer_impact = aHammer_impact.Play();
    Hammer_impact.SetRoomLocation (800, 180);
  }

rongel

Quote from: Khris on Wed 17/10/2018 15:53:36
Instead of using eRepeat, use repeatedly_execute:

Hey, that seems to work, thanks Khris!

I had to use repeatedly_execute_always() so that it is playing in the background, and change the frame delay to 0 (otherwise the sound was playing several times at once). But everything seems fine now. An easy fix for once!
Dreams in the Witch House on Steam & GOG

Khris

Right, setting the frame delay to 0 is one way that'll work. Here's another:

Code: ags
int prevFrame;

void repeatedly_execute_always() {
  if (cBlackSmith.Frame == 4 && prevFrame != 4) {
    AudioChannel Hammer_impact = aHammer_impact.Play();
    Hammer_impact.SetRoomLocation (800, 180);
  }
  prevFrame = cBlackSmith.Frame;
}

SMF spam blocked by CleanTalk