How do I use audio?

Get help using Construct 2

Post » Sun Sep 18, 2016 11:00 pm

I really need help with this.
I have tried making this work and i just can´t understand why.
Im trying to simply make a button that controls the state of the audio.
Since i cant post capx or links im just gonna write down the "code" that i have inserted.

I have a very basic sprite with 2 animation frames. In the first frame it´s color is blue and in the second its black.
I have a single numerical type global variable called sound.
The music file format was wav. so it was converted just fine.

Heres what i have "coded":
Global number Sound= 0
System - On start of layout - Stop Sprite animation.
- Play Audio_File looping at volume 0 db( tag "Music")
Touch - On touched Sprite - Add 1 to Sound.
System - Sound > 1 - Set Sound to 0.
System - Sound=0 - Set animation of Sprite to 0
- Play Audio File looping at volume 0 db( tag "Music")
System - Sound=1 - Set animation of Sprite to 1
- Stop "Music".
End of Code

However this doesnt work and i simply dont understand why or what im doing wrong.
Someone help me pls i have been on this problem for hours now :cry:
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Mon Sep 19, 2016 12:19 am

Hi, Husui.

Take a look at my examples.

The sound will play stacked, if you don't put 'System -> Trigger Once'.

I had to extend the Sound global variable to 2 in order to avoid the sound from playing automatically while at 0.

This capx example one is based on your codes. Notice we need to tap the Blue square twice to get it working.

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

And this one is mine.

Notice I've put a Wait of 0.1 second to make this work. I don't know what 'Wait 0.1 second' does in the C2 background, but it allowed me to do a lot of things that got me stuck for days while developing games.

https://www.dropbox.com/s/pt09ng9fpzgxa ... .capx?dl=0
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Mon Sep 19, 2016 12:44 am

Thanks for the reply. However i believe the problem lies when i try to use a music and not a sound.
I tried it again and did exactly the same events that you posted on your examples and it still doesnt work.
it works if i use a sound like for example the mario jumping sound but when i try to get construct to play a music instead i simply hear nothing.
I´m really confused...
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Mon Sep 19, 2016 1:42 am

Husui wrote:Thanks for the reply. However i believe the problem lies when i try to use a music and not a sound.
I tried it again and did exactly the same events that you posted on your examples and it still doesnt work.
it works if i use a sound like for example the mario jumping sound but when i try to get construct to play a music instead i simply hear nothing.
I´m really confused...


You're welcome, Husui. :mrgreen:

That's odd. Unless the music file was not imported properly, it should work.

Please upload the capx file to Dropbox, if possible.

https://www.scirra.com/tutorials/42/upl ... to-dropbox
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Mon Sep 19, 2016 2:48 am

Message: Husui can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I think i did it right if so here it is:
https://www.dropbox.com/s/mpt5jk0cp9z1v ... .html?dl=0
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Mon Sep 19, 2016 2:56 am

Ouch, the URL got cut off.

Please remove https:// from the URL and post the address like below.

dropbox (dot) com/s/blbdpw4vt80qdla/Gmoney%20-%20road%20-%20sprite%20animation%20V4.capx?dl=0
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Mon Sep 19, 2016 3:08 am

huh i dont really know how to.
never used dropbox before i tried to send you a pm but not even that i am allowed to do.
these restrictions are really annoying to say the least, all i wanted was help...
sorry gmoney im a really big noob.
B
26
S
14
G
8
Posts: 49
Reputation: 6,250

Post » Mon Sep 19, 2016 3:56 am

Husui wrote:huh i dont really know how to.
never used dropbox before i tried to send you a pm but not even that i am allowed to do.
these restrictions are really annoying to say the least, all i wanted was help...
sorry gmoney im a really big noob.


No problem, Husui. :D

I'm so sorry for the troubles you had to go through with Dropbox. :(

I have updated the following capx file with a music file.

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

The capx file is designed to take any music or sound files without any issues and I have tested to confirm they're working.

The music files destined for the C2 use must be encoded in to two formats: Ogg Vorbis (.ogg) and MPEG-4 AAC (.m4a).

Based on my experience, it's best to use .WAV files as the source file before converting them to .ogg or .m4a.
B
11
S
6
G
15
Posts: 256
Reputation: 9,207


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests