Jump to content


Photo

Adjusting sounds for spearate instances


  • Please log in to reply
1 reply to this topic

#1 DogMakina

DogMakina

    GMC Member

  • New Member
  • 14 posts
  • Version:GM8

Posted 31 March 2012 - 11:30 PM

I'm working on a 2d platformer where I want to adjust the sound given off by individual instances of a barrel object according to the distance of the player.

The code works well with only one instance of the barrel object, but doesn't when there are several instances.
Example: The player stands right by one barrel and shoots a barrel standing far away, the hit sound plays as loud as if the player were standing next to it. Also, equally as often the sound is very low even though the player shoots a very close barrel.

This code is in the step event of the barrel object, and the "obj_guybody" is the player character.

I've never been good with code though I understand most of the basic stuff. I guess I need to alter the code to only affect the current barrel being hit.

if distance_to_object(obj_guybody)>3000
{
sound_volume(snd_metalthump1,0)
sound_volume(snd_metalthump2,0)
sound_volume(snd_metalthump3,0)
}
else
{
Vol=1
Vol-=distance_to_object(obj_guybody)/2000
sound_volume(snd_metalthump1,Vol)
sound_volume(snd_metalthump2,Vol)
sound_volume(snd_metalthump3,Vol)
}

  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9314 posts
  • Version:Unknown

Posted 31 March 2012 - 11:41 PM

In GM, there's no such thing as a sound instance. Every copy of a playing sound is just that--an exact copy. So when you change the sound volume, you're changing it for all copies of the sound.

Sadly, there's no way to get around this using just GM. But there's some good news: there are many DLLs for audio playing, and most (if not all) of them support individual sound instances (which can be manipulated independently). Check the DLLs forum for audio DLLs; I prefer FMOD myself, but find one you like best. There are many to choose from :) .

-IMP
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users