Fading sounds out and in depending on the region

TigroTigro Member Posts: 32

I'm still new to gamesalad so I don't really have a clear idea on how I should implement for my game. Namely, I'm making a platformer with different "rooms" in the same scene between which you can freely walk. I also have some sound effects exclusive to the rooms to give the right ambiance and some music independent from them like the main level music. What's the easiest way to make the game play the right sounds in the right portions of the level and smoothly change the currently played ones to them with some transition?

Comments

  • ookami007ookami007 Member Posts: 581

    I implemented something similar to this in my platformer template.

    To have a sound only play when the player is near, try this:

    Create two reals at the game level ... game.playerX and game.PlayerY and constrain them to the player's X,Y in the player actor

    On the actor playing the sound, create a real called playerRange
    Constrain playerRange to magnitude(abs(game.playerX - self.X), abs(game.playerY - self.Y))

    That gives you the range from the object to the player

    With that information, you can add a rule to only play the sound if the player is withing X pixels... and if you want to do some calculations, you can set volume to be softer based on distance.

    Say your max distance was 200. Divide that by 10 to get your 10 increments... in this case 20. Then you could set it to (200-x)/20 *.1... so if they are at 100 that's (200-100)/20 (5) *.1 or .5 ... which is about half volume. If they move closer, say 60... that's

    (200-60)/20 (7) * .1 or .7 so it's louder.

    If they go further away... say 160, that's (200-160)/20 (2) *.1 = .2 so much softer

    You will probably need to do some sort of constrain to keep it up to date.

  • TigroTigro Member Posts: 32

    Wow, sounds perfect! Thanks a lot, will surely try to do it, hopefully it won't turn out impossible for my skill level.

Sign In or Register to comment.