Sounds

Get help using Construct 2

Post » Thu Dec 13, 2012 2:00 pm

Hi I was just wondering if there is a way to place sound files in some sort of array, or have a function to play random sound files?
B
20
S
2
Posts: 257
Reputation: 2,431

Post » Sat Dec 15, 2012 8:03 am

Bump
B
20
S
2
Posts: 257
Reputation: 2,431

Post » Sun Dec 16, 2012 4:14 am

Most people tend to avoid sound questions on this site for some reason. I don't, because I'm a sound guy myself.

However, I don't know the answer because I haven't studied arrays yet. It's on my to-do list.

For functions, you can always put sound event in a function. However, for random sounds, check out these search results...
https://www.scirra.com/forum/search?q=random+sounds.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Sun Dec 16, 2012 3:59 pm

Thank you so much, I appreciate the link. I tried out Yann's example using "choose" and it worked like a charm. I now need to do a bit of poking around to find out how to keep a chosen sound file from being chosen twice in a row. I think I've seen it applied to sprite creation, so probably works for sounds too.
B
20
S
2
Posts: 257
Reputation: 2,431

Post » Sun Dec 16, 2012 4:27 pm

I don't remember what is my example but you can keep a list of sound, and pick randomly without repetition like that:

[code]+System: On Start of layout
   -> Array: set size to (0,1,1)
   -> Array: push back soundA.wav on X axis
   -> Array: push back soundB.wav on X axis
   -> Array: push back soundC.wav on X axis
   -> Array: push back soundD.wav on X axis
   -> ...

+On whatever
   local number randomIndex = 0
   -> System: randomIndex = floor(random(Array.Width))
   -> Audio: play sound Array.At(randomIndex)
   -> Array: delete at index randomIndex)[/code]

The delete function of the array object delete the value at the index and shrink the array by 1 to fill the gap. So the Array.Width will decrease until you played every sound in the list.Yann2012-12-16 16:34:07
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Dec 16, 2012 4:34 pm

Wow Awesome Yann!
I'll give it a try.
B
20
S
2
Posts: 257
Reputation: 2,431

Post » Sun Dec 16, 2012 4:37 pm

For your soundplay list. I'm not because I haven't played with sound much, but I assumed that sound files had both a name(unique) and tag(shared?). So that if you play by tag it would then just play all of them with the tag.

I guess the best way is to experiment with that
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, abdalghani, imothep85, Marxally, Virpoja and 27 guests