Alternate audio sounds?

Get help using Construct 2

Post » Sun Sep 01, 2013 10:18 pm

[QUOTE=blackhornet] Don't include the extension. Convert the random number to int. Make sure your range is correct.
http://blackhornettechnologies.com/Construct2Stuff/RandomShotSound.capx[/QUOTE]

thanks.. yeah I was just putting .ogg in there to show it was a sound file..
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Mon Sep 02, 2013 12:33 am

@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.   
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Post » Mon Sep 02, 2013 4:43 am

nice! did not know about choose.. thanks!

that's easier than doing "gun" & floor(random(3)) and probably more efficient?
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Mon Sep 02, 2013 5:43 am

the efficiency (in this case) is most likely negligible so you should do what reads best :)keepee2013-09-02 06:25:21
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Sep 02, 2013 4:43 pm

@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...
composer - multimedia artist
www.eli0s.com/en/
B
68
S
26
G
4
Posts: 1,146
Reputation: 9,649

Post » Tue Sep 03, 2013 3:35 pm

You can't create patterns with choose() or random() though.
B
66
S
27
G
24
Posts: 968
Reputation: 18,546

Post » Tue Sep 03, 2013 4:15 pm

[QUOTE=Magistross] You can't create patterns with choose() or random() though.[/QUOTE]

yeah, that's why I used your --- Set counter to counter % 3 + 1 idea

although I changed it to 6 which makes more sense in my case... since I have bullet firing sounds, then every 6th event it changes the sound slightly.

for patterns maybe a better idea would be to make a Function and somehow make it dynamic so that you could use it for multiple things.   Make sure all sound files are named the same except for the number.

so pass the function: filename (minus the number), the number of sounds, then the pattern to play and the counter which tells us where we are in the pattern.

i.e.
Call Function ("PlaySoundPattern","gun", 2, "6:1", PlayerShootcounter)

I'm new to Functions in C2 can anyone help here? how would you send a pattern information to a function so that it understands how to play them? patterns like 6:1 or 3:2 or 1:2:1 if there are 3 sounds etc..? how to make it dynamic?
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Tue Sep 03, 2013 4:15 pm

If you want a pattern, your best best will be to load the file names into an array (at the start of the layout or game, for instance) lie 0,1 = gun1, 0,2 = gun1, 0,3 = gun2 and so on. Then just play file at each of those locations, but add 1 to the y index each time. Then, if the y index surpasses your highest file name, set it back down to your lowest. It's actually how I do footsteps on my game, though I randomize baed on array values. Then I can change the file names out in the array depending on what surface you are walking on, but the command to play the footsteps keeps on going.
B
103
S
38
G
19
Posts: 962
Reputation: 17,986

Post » Tue Sep 03, 2013 4:35 pm

[QUOTE=C-7] If you want a pattern, your best bet will be to load the file names into an array .[/QUOTE]

ahh nice idea using arrays... so if I were to make it a Function I could pass the array bounds.

say I had a 7 pattern of: 1 1 2 1 2 1 2

CallFunction("PlaySoundPattern",PlayerShoot_arrraysounds, 7, PlayerShootCounter)

CallFunction("PlaySoundPatter",BadGuy_arraysounds,3, BadyGuyShootCounter)

although should probably make array bounds a constant so you can change it easy.


C7, you must do this for footsteps on different materials..grass, woodfloor, cement floor etc...?
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Tue Sep 03, 2013 4:42 pm

[QUOTE=jobel] [QUOTE=C-7] If you want a pattern, your best bet will be to load the file names into an array .[/QUOTE]

ahh nice idea using arrays... so if I were to make it a Function I could pass the array bounds.

say I had a 7 pattern of: 1 1 2 1 2 1 2

CallFunction("PlaySoundPattern",PlayerShoot_arrraysounds, 7, PlayerShootCounter)

CallFunction("PlaySoundPatter",BadGuy_arraysounds,3, BadyGuyShootCounter)

although should probably make array bounds a constant so you can change it easy.


C7, you must do this for footsteps on different materials..grass, woodfloor, cement floor etc...? [/QUOTE]

Right. I have a different set of footstep sounds for different things like grass, sand, cement, dirt, wood, etc.
B
103
S
38
G
19
Posts: 962
Reputation: 17,986

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Twili and 1 guest