How do I play the audio properly?

0 favourites
  • 13 posts
From the Asset Store
This Student Workbook uses both Construct 3 & 2 encoding. It supplies client-side & php "back-end" encoding.
  • Hi all

    Like the title said, how do I play the audio properly? I am making a game here, when the character get nearer to an object, the audio is getting louder and when the character is far away from it, the audio becomes softer. I tried to search for tutorials in youtube, but I can't find it.

    I know there is a template in Construct 2, applied to my game, but a bit different on what I expected. The template name is Positioned Audio.

    The sound played on start of layout although I didn't set it in my sheet. What I am trying to say is, when the character is kinda near to the sprite, the audio starts to play according to the audio set to it and make the behaviour like I said above.

    Here is sample capx

    goo.gl/wha8nk

  • I'm not sure how positioned audio works, I thought it adjusts the volume for left and right channels (for stereo effect). But I might be wrong.

    Anyway, here is an example of how you can change volume depending on the distance between two objects:

    https://www.dropbox.com/s/th46kawcflcnp ... .capx?dl=0

  • That works perfectly! Thank you!

    But is it possible when the character is within the gold object area, the audio will play? Not to play the audio on start?

  • Sure, you can start audio playback on collision with some sprite.

    Or compare distance(character.x, character.y, gold.x, gold.y)

    Say, if distance <500, start audio.

    If distance >600, stop audio.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Do you mean like this?

    goo.gl/DwSAkd

    Or should I make a different global variable for the character distance?

  • Not exactly...

    Your variable DistanceSoundBomb changes from 0 (complete silence) to 1 (full volume).

    If distance between objects is 1000 pixels or more, then it will be 0.

    You can change "1000" in that formula to 50 or whatever number you want.

    For playing/stopping sound you should use these events:

    System->Compare two values -> distance(detector.x, detector.y, bomb.x, bomb.y) is less than 50 -> Play sound

    System->Compare two values -> distance(detector.x, detector.y, bomb.x, bomb.y) is greater than 60 -> Stop sound

  • Do you mean like this? If I put it like this, there's no audio playing, only the explosion and gold collected.

    goo.gl/CPJSR4

  • No, you created something very weird <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    I forgot to tell you that before playing the sound, you should check that it's not already playing.

    Anyway, here is the working example:

    https://www.dropbox.com/s/qsoe2gzq78h3c ... .capx?dl=0

  • That worked just like I wanted! Thank you!

    But one more problem though.. Since my bomb and gold sprite will spawn at random places, how to make the sound area follow the random spawned location?

  • You can add Drag&Drop behavior to the Boombox sprite in my example, move it around and see if the sound area follows it. (it does)

  • What I am trying to say was.. I made the object gold and bomb to spawn at random places, I need the audio played is also available at the spawned place, not at only one spot.

    I tried to put a random(Bomb.X) at the compare two values, but is sounds very weird, just like a buffering beep or stuck beep..

    https://goo.gl/5uyZFA

    And since the bomb sprite will spawn a lot more, the sound is only available at one sprite, not all of them

    Here is the current file

    https://goo.gl/1yRdYt

  • Oh, ok, here is the updated demo:

    https://www.dropbox.com/s/0ffgp2436nwxy ... .capx?dl=0

  • That worked perfectly!! Thank you!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)