Alternate audio sounds?

Get help using Construct 2

Post » Sat Aug 24, 2013 6:54 am

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...


B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Sat Aug 24, 2013 6:57 am

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...
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Sat Aug 24, 2013 8:11 am

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 :)
B
15
S
6
G
3
Posts: 35
Reputation: 3,982

Post » Sat Aug 24, 2013 1:25 pm

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..

B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Fri Aug 30, 2013 4:45 pm

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...
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Post » Fri Aug 30, 2013 5:01 pm

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")Magistross2013-08-30 17:03:24
B
74
S
31
G
26
Posts: 994
Reputation: 20,198

Post » Sat Aug 31, 2013 4:38 pm

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...
B
5
Posts: 12
Reputation: 374

Post » Sat Aug 31, 2013 5:07 pm

Don't include the extension. Convert the random number to int. Make sure your range is correct.
RandomShotSound.capxblackhornet2013-08-31 17:08:22
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Sat Aug 31, 2013 5:11 pm

Way cool, thank you!
B
5
Posts: 12
Reputation: 374

Post » Sun Sep 01, 2013 10:06 pm

[QUOTE=Magistross] (The pattern would be "gun1.ogg" - "gun1.ogg" - "gun2.ogg")[/QUOTE]

that would work.. thanks!
B
100
S
33
G
16
Posts: 1,204
Reputation: 16,865

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests