SOUND VOLUME DEPENDING ON DISTANCE

RPG Maker XP

Want that sweet effect of sound volume increasing, when player is aproaching a sound source? Here's the script for that.

  • Bogo
  • 05/22/2015 04:03 PM
  • 9996 views
Put the script code in Game_Map class. To make sure it will work, place it under 'setup' function, after lines:
...
@scroll_direction = 2
@scroll_rest = 0
@scroll_speed = 4
end

>> here goes the script <<

To use the script click 'Script...' option on the third tab of events creator and input text:

$game_map.playDistanceAudio(eventID, soundFile)

- eventID is an ID of an event to which player will approach (you can put this event over a fireplace, for example, or over a waterfall)
- soundFile is a path to a sound file you want to be played, when player is getting close to the event (fireplace, waterfall...).

Exemplary usage of the script:
$game_map.playDistanceAudio(1,'Audio/BGS/011-Waterfall01')

I tried to make the script optimized, so it won't use much of processor power, hence the code doesn't look neat. Don't mind it;)
More detailed tutorial on how to implement the script comming soon.

Posts

Pages: 1
Thank you for script, very useful not to make a mess of sounds on a map!
It works only in parallel process, 'cause this function need to be called permanently to detect the distance.
I'm happy it's useful for you!

You're right, it's meant for a parallel process. I've uploaded a tutorial in which I explain in detail
how to use that script and apply some optimizations, so it won't kill your frame rate:)
You can check it here: http://rpgmaker.net/tutorials/1143/

Cheers, Bogo
Hello again (:
I have an idea how to make script using easier, but i don't have enough skills in Ruby, but it works, in distance BGS event i write kinda script:

if ($game_map.getDistance(5)<=13)
$game_map.playDistanceAudio(5,
'Audio/BGS/broken_light')
end

so, it helps to play next basic BGS sounds and don't stop this parallel process event.
(also good to use your other script on moves conditions for optimization)

I'v tried to use script in my game today, but it have trouble with other BGS(basic script PlayBGS), i read about two sounds problem in your tutorial.
I've tried to use Audio.bgs_stop, but it didn't help.

And if i'm at distance 13, BGS distance script stops and after that my basic BGS Play works good.
In this basic BGS play event i write script:"Audio.bgs_stop" and when i'm back to distance script event it have big lag, why?
And if i Erase that event(basic BGS play), and go back to distance script - it works ok, so, every time i have to erase basic BGS events, why Audio.bgs_stop doesn't help?
Your 'if' is very useful indeed, it will definitely increase performance.

I'm not a Ruby veteran neither, but here are my guesses:
- Maybe the other sound is still called somewhere by some event?
- The other thing that comes to my mind, is that although you stop the other sound (Audio.bgs_stop), the script still comes in first hence the conflict.
Yes, it was the second one, simple problem.
Thank you for help and for the script.
I will credit you in the game :)
That's great, glad I could help;) Good luck with your game!
Pages: 1