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

0 favourites
  • 5 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • 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.

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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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, .

  • You can try the attached capx, click the button to toggle whether the button on or off.

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)