How do I code a button to turn music on and off?

Get help using Construct 2

Post » Wed Sep 10, 2014 12:52 am

Basically I get the feeling this is like an on and off switch but I can;t seem to figure out how exactly I execute this.
So anyone have a sample or can direct me to a tutorial?
thanks.
and preferably with visuals too please.
B
10
S
1
Posts: 69
Reputation: 641

Post » Wed Sep 10, 2014 1:15 am

I don't think there is an automatic on/off switch. We can create it though by using variables. For example, create a variable called VarMusic. Than at start of layout, set if VarMusic = 1, play your song. Than in page that has the music on off option, just set it so that when the player turns music on, VarMusic = 1, and when they turn it off, VarMusic = 0.
B
45
S
23
G
31
Posts: 693
Reputation: 20,612

Post » Wed Sep 10, 2014 2:08 am

Alternatively, when you play an audio file you can give them a tag, which means you can target that tag for switching audio on and off. If you give the background music a tag such as "mus_background_01", you can create an Event upon the button click to trigger Audio -> Stop "mus_background_01". Then you save having to make a variable and processing a condition, :).
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Wed Sep 10, 2014 6:28 am

You can try the attached capx, click the button to toggle whether the button on or off.
You do not have the required permissions to view the files attached to this post.
B
23
S
9
G
3
Posts: 114
Reputation: 3,794

Post » Wed Sep 10, 2014 12:17 pm

You need: Audio object, button, boolean variable or 0/1

How to:
1. On button clicked >do> ---
Sub1: Variable = 0 >do> play music "name" on tag "music"
Sub2: Variable = 1 >do> stop music on tag "music"

Done
B
23
S
5
G
4
Posts: 143
Reputation: 3,262


Return to How do I....?

Who is online

Users browsing this forum: amazingdream and 22 guests