Alternate audio sounds?

0 favourites
From the Asset Store
Make your gore effects come to life with this sounds! :D
  • Anyone know of a good way to alternate audio sounds for the same Action?

    like firing a weapon, it would be nice to have a different sample in there so it doesn't sound like it's "stuck"...or explosion sounds, I'd like to vary it up.

    thanks...

  • to clarify...

    --->|Keyboard| on press Space Bar - play "gun1.ogg"

    I'd like to have gun2.ogg, gun3.ogg and randomly alternate playing those sound when the player hits the space bar...

  • How about...

    --->|Keyboard| on press Space Bar - play "gun"&random(3)&".ogg"

    I don't know if I wrote it right, but you get the idea. Basically make the number on the file you're playing generated randomly everytime you press space

    Hope it helped :)

  • can you do that with filenames?   hmm that would work... and if I want the sounds to fire in a specific order I guess then I'd have to flag it.. cool thanks! I'll try it..

  • what about a pattern?

    for example, vary the gun sound after 3 times:

    gun1.ogg, gun1.ogg, gun1.ogg, gun2.ogg

    I guess I can make an array and put "1" in the first 3 and "2" in the last one and cycle through them.. but not sure if that's the best way..

    is there way to do:

    on Start set counter to 1

    if Keyboard = spacebar   spawn bullet

                                           if counter < 3

                                              play sound "gun1.ogg"

                                              add 1 to counter

                                           else

                                              play sound "gun2.ogg"

                                              set counter to 1

    I've tried to do this, but it won't let me build the syntax like this...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try this expression :

    Play sound : "gun" & (counter < 3 ? "1" : "2") & ".ogg"

    Then set the counter with this expression :

    Set counter to counter % 3 + 1

    (The pattern would be "gun1.ogg" - "gun1.ogg" - "gun2.ogg")

  • Is there a way to make a simple version work like "gun"&random(3)&".ogg"? I tried this in the "Play (by name)" Action and nothing happens...

  • Don't include the extension. Convert the random number to int. Make sure your range is correct.

    RandomShotSound.capx

  • Way cool, thank you!

  • (The pattern would be "gun1.ogg" - "gun1.ogg" - "gun2.ogg")

    that would work.. thanks!

  • Don't include the extension. Convert the random number to int. Make sure your range is correct.

    http://blackhornettechnologies.com/Construct2Stuff/RandomShotSound.capx

    thanks.. yeah I was just putting .ogg in there to show it was a sound file..

  • jobel

    You can also use the "choose" expression.

    Make sure you select the "Play(by name)" action, set the folder in which the audio files exist within your project and in the "Audio file name" field write something like this:

    choose("gun1", "gun2","gun3")

    Construct will play the above 3 audio files at random every time you trigger the action.

  • nice! did not know about choose.. thanks!

    that's easier than doing "gun" & floor(random(3)) and probably more efficient?

  • the efficiency (in this case) is most likely negligible so you should do what reads best :)

  • jobel

    To be honest, I think blackhornets way is more robust, since you don't have to write down every last name of the sound files you want to use.

    The "choose" method is easier (I think) if you have a few files.

    Also, it doesn't restrict you with naming/prefixing the audio files in any particular way, since you call them individually by their full name.

    Performance-wise, I don't know which is faster...

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