"Distant" Sound Effects

Non-platform specific questions.

"Distant" Sound Effects

Postby happyjustbecause » Fri Dec 14, 2012 12:31 am

Hello again!

I'd like to add something in my game so there's an increased feeling of space and distance. I want to make it so that the farther away an explosion or something occurs, the less loud it is, this doesn't have to be applied to everything just big things like explosions.

I've already done this, but in a sloppy if statement ridden way. I'm just wondering if there's a better way of doing it, similar to what I just did with the hologram power icon perhaps?

Here's the code I'm using:

Explosion -> Create Actor -> Script Editor

Code: Select all
Distance=distance(x,y, Bounding_Box.x, Bounding_Box.y);
highest_BombExplosion=20;
switch(animindex)
{
    case 0:
    ChangeAnimation("Event Actor", getAnimName(Bomb_E_Upgrade), NO_CHANGE);
    if(Distance>=1100)
    {
        PlaySound2("data/Bomb_Explosion.wav", SFX_Volume/2.5, 1, 0);
    }
    else
    {
        PlaySound2("data/Bomb_Explosion.wav", SFX_Volume, 1, 0);
    }
    break;

    // and so on
}
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: "Distant" Sound Effects

Postby skydereign » Fri Dec 14, 2012 12:56 am

I assume you want the sound to be gradual, opposed to close and far. Therefore you can set it up almost exactly like you did the hologram. Clearly the blast would sound the loudest at the point of the player (or perhaps the screen itself if you prefer). All you need now to setup the range is to determine at what point does the explosion no longer make noise.
Code: Select all
int dist = distance(x, y, Bounding_Box.x, Bounding_Box.y);
double vol = SFX_Volume*(2000.0-dist)/2000.0;
// since PlaySound2 seems to play noises with negative volume, you'll need to something like this
vol = max(vol, 0); // you might recall this will set vol to 0 if vol<=0
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: "Distant" Sound Effects

Postby happyjustbecause » Fri Dec 14, 2012 2:37 am

Yeah, I want the sound to be gradual and be more than just 2 settings.

So I have to set up the range that the explosion won't make noise anymore. I do this by setting the vol=max? Or by setting the double vol = SFX_Volume...

Is the 2000 the current distance that the sound will no longer play, or is it 0?

An once that's set up, instead of having:

Code: Select all
PlaySound2("data/Bomb_Explosion.wav", SFX_Volume, 1, 0);


I'll have:

Code: Select all
PlaySound2("data/Bomb_Explosion.wav", vol, 1, 0);


Right?
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score

Re: "Distant" Sound Effects

Postby skydereign » Fri Dec 14, 2012 2:43 am

By the way, I edited the code a bit. I forgot to add the /2000.0 to the second line.

happyjustbecause wrote:Is the 2000 the current distance that the sound will no longer play, or is it 0?

If dist is 2000, then vol is set equal to 0, while if it is equal to 0, it is set to SFX_Volume.

happyjustbecause wrote:An once that's set up, instead of having:

Code: Select all
PlaySound2("data/Bomb_Explosion.wav", SFX_Volume, 1, 0);


I'll have:

Code: Select all
PlaySound2("data/Bomb_Explosion.wav", vol, 1, 0);


Right?

Right. You could instead not use the vol variable and write that code in the function call, but it looks cleaner this way.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: "Distant" Sound Effects

Postby happyjustbecause » Fri Dec 14, 2012 2:57 am

Oh, okay, with that edit to the code it makes much more sense. Alright cool, thanks again. I think this is another worthy addition to the game.
For small creatures such as we the vastness is bearable only through love.
-Carl Sagan

Night Knight Development Thread
User avatar
happyjustbecause
 
Posts: 267
Joined: Tue Jul 26, 2011 3:10 pm
Location: Frazier Park, Ca
Score: 15 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron