Jump to content

Sound Source delays after Play()


Recommended Posts

When bullet hits wall a sound source will be created and play.

soundSource:SetSound(sound.bullethit)
soundSource:SetVolume(10)
soundSource:SetRange(15)
soundSource:SetPosition(self.bulletPickInfo.position)

It is ok when I stay near the impact position but if it is far from me, the sound is delayed then played when I get in range.
How can I fix this bug ?

 

  • Like 1
Link to comment
Share on other sites

I will look into this more closely. There is an optimization that skips sounds that are played out of range.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Okay, I am moving the check into the entity EmitSound() method, which will return nullptr if a one-time sound is played out of range:

#ifdef LEADWERKS_5
	shared_ptr<Source> Entity::EmitSound(shared_ptr<Sound> sound, const float range, const float volume, const float pitch, bool loopmode, const bool checkdistance)
#else
	Source* Entity::EmitSound(Sound* sound, const float range, const float volume, const float pitch, const bool loopmode, const bool checkdistance)
#endif
	{
      	if (checkdistance)
        {
			if (sound->channels == 1 && loopmode == false && range > 0)
			{
				if (this->GetPosition(true).DistanceToPoint(SoundDriver::GetCurrent()->listener) > range)
				{
					return nullptr;
				}
            }
		}
		...

There is a checkdistance parameter added. By default this is enabled, but you can disable it if you want.

This will be in the next build on the beta branch.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Josh locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...