Button to Turn Music On and Off

JoshKahaneJoshKahane Member Posts: 470
edited November -1 in Working with GS (Mac)
Hi

I am trying to create a button which when touched turns music off (volume to 0) and when pressed a second time comes back on of course. I have been using GS a long time now and I can't believe I can't this to work, hehe. You would think it was simple, as soon as I am told it I will think "Ahhh of course!".

Anyway I am having issues, Im doing it wrong. How can I get this working? Thanks.

Comments

  • BeyondtheTechBeyondtheTech Member Posts: 809
    On a side note, you should pause the music instead of setting the volume to 0. You can always use the extra CPU for the game instead of having the device decompress and play an audio file you'll never hear.

    Pausing the music can also solve your dilemma. What does your Rule currently look like?
  • JoshKahaneJoshKahane Member Posts: 470
    Good point about performance although I have my music play at different points in the game as well, so it would only stop the music until a certain point. This is why I chose to mute it rather than pause.

    Currently I have when pressed change attribute 'Music' to false. Then I have a second rule the same in reverse, if touched become true. However this just makes it loop, it instantly goes off to on. So it doesn't work and I can't think of anyway to stop this.
  • JoshKahaneJoshKahane Member Posts: 470
    More simply I would just like to know how to make a button which when pressed changes the volume to 0 and when pressed again to full (1) and visa versa. Thanks.
  • WeswogWeswog Member Posts: 1,171
    If you need any more help here is a tutorial with a video tutorial I made:)
    http://gamesalad.com/wiki/how_tos:gsc_turn_sound_on_off#how_do_i_turn_music_on_and_off

    Cheers, Weswog
  • HunnenkoenigHunnenkoenig Member Posts: 1,173
    Weswog, could you please use some other stuff for video? Like youtube or such.

    If I am on Windows and Firefox (have no internet on my hackintosh), I can't see your video(s), because a missing plugin, which I can't install, because nobody knows, what plugin that supposed to be.

    Thanks!

    ----

    I would be interested in a slider for changing the music's volume.

    Anybody with an idea, how to do that? I assume, I would have to use "change attribute" sound every 0.1 seconds by 0.1 or so...

    But how do I do the slider?
  • JoshKahaneJoshKahane Member Posts: 470
    Ahh yep thats how I ended up doing it Wesong, sorry I didn't warn you before you went and created the tutorial but that will help others a lot I expect.

    I ended up using two buttons which is easy but I would have preferred one button which does both on and off thats all.
  • ORBZORBZ Member Posts: 1,304
    i haven't tried to do this but shouldn't it just be as simple as a global game bool musicOn and a rule that says:

    when musicOn = true:
    Play Music (resume is one of the options on the Play Music list)
    otherwise:
    Pause Music

    Then a button that toggles musicOn between true and false

    Am i missing something?
  • WeswogWeswog Member Posts: 1,171
    I already had the tutorial made before his post and here is the youtube video link:)


    Cheers, Weswog
  • JoshKahaneJoshKahane Member Posts: 470
    Ahh guess I missed it, sorry Wesong! But ORBZ my issue is that when I have rules on the same button to switch back and forth it creates a loop and so is always either on or off. Hope that makes sense.
  • ORBZORBZ Member Posts: 1,304
    Use the touch released event and the modulus operator to toggle between 0 and 1

    Change attrib state=(state+1)%2
  • scrapee_netscrapee_net Member Posts: 424
    Hello ORBZ, I know this is a very old topic, but I have the sane doubt. How to use the same button, when pressed change the image to off and the music to off, and then when pressed for the second time change to on again.

    I didnt understand what you mean with modulus operator.
Sign In or Register to comment.