How to make sound on the menu...?

Add someAdd some Member Posts: 48

Hey guys i want make a sound on the menu, also make a button to this sound when i click this button make a sound off and when i click button once again make a sound on, also i want when i click this button to make a sound off make this button hidden and when i click this button once again to make a sound on make this button visible, and this sound i want him to work on levels also...?

Comments

  • dapiondapion Member, PRO Posts: 353

    Make a global Index attribute, called Music On/Off
    In your Button actor this rule:
    If touch is pressed > Change.attribute (Game.Index) to (Game.Index+1)%2
    So you have by every click a switch between 0 & 1.

    Go into your music actor and make this rule...
    If attribute Game.Index = 0
    Music off

    If attribute Game.Index = 1
    Music on

    With the same attribute you can switch your On/Off between hide/visible.

  • SocksSocks London, UK.Member Posts: 12,822

    @dapion said:
    Make a global Index attribute, called Music On/Off
    In your Button actor this rule:
    If touch is pressed > Change.attribute (Game.Index) to (Game.Index+1)%2
    So you have by every click a switch between 0 & 1.

    Go into your music actor and make this rule...
    If attribute Game.Index = 0
    Music off

    If attribute Game.Index = 1
    Music on

    With the same attribute you can switch your On/Off between hide/visible.

    You could simplify this somewhat, lose a few rules and attributes by just changing the music level directly.

    I'd put this in the button:

    If touch is pressed, change music volume to 1-music volume.

    You could also hide/show the on off button the same way (change alpha to 1-alpha).

  • dapiondapion Member, PRO Posts: 353

    @Socks
    This is of course a solution :-)
    I had made the proposal because I enjoy working with Global attributes.
    Possible one needs this perhaps later ...

  • SocksSocks London, UK.Member Posts: 12,822

    @dapion said:
    Possible one needs this perhaps later ...

    true !

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited October 2015

    Change musicVolume to sin((sqrt((1-musicVolume)*90)/2)*180)

    also works, not so @Socks? :D Please stay in character!

  • SocksSocks London, UK.Member Posts: 12,822

    @Hopscotch said:
    Change musicVolume to sin((sqrt((1-musicVolume)*90)/2)*180)

    also works, not so Socks? :D Please stay in character!

    Unfortunately that wouldn't work, if it started out at 0 it would return 0, so would never change.

    And if it started out at 1 it would return 0.72 which would rob us of 0.28 of the dynamic range available to GameSalad, and worse still on the next press of the button it would return 0.078, then -0.85 . . . , it would be math mayhem, someone must pay for this outrage.

  • SLOCM3ZSLOCM3Z Member Posts: 797

    @Hopscotch said:
    Oh but it does, dear sir!

    Did you just argue with @Socks?

  • SLOCM3ZSLOCM3Z Member Posts: 797

    @Add some You could use the not() function like this:

    Rule
    -touch is pressed
    :do:
    change attribute game.PlayMusic :to: not(game.PlayMusic)

    Then have another rule that says

    Rule
    -if attribute game.PlayMusic = true
    :do:

    Play music

    :otherwise:
    Stop music

  • Add someAdd some Member Posts: 48

    Guys anyone has a video about this...?

  • SLOCM3ZSLOCM3Z Member Posts: 797
    edited October 2015

    Use the method I showed you :)

  • SocksSocks London, UK.Member Posts: 12,822

    @Hopscotch said:
    Oh but it does, dear sir!

    Oh damn, now I'm gong to have to calculate it properly, and you being Hopscotch probably means you are right . . . . back in a couple of minutes . . .

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited October 2015

    @Socks said:
    you being Hopscotch probably means you are right

    This used to be my opener when meeting a girl, hence leading to me having lots of time to pursue more intellectual interests, aaand culminating in confirmation of the statement. B)

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2015

    @Hopscotch said:
    sin((sqrt((1-musicVolume)90)/2)180)

    Ok, I'll show you my thinking here . . . .
    (The goal is to jump between 1 and 0 ? On and off ?)

    . . . . . . . . . .

    So, let's start with music volume being set to 0 . . . . sin((sqrt((1-0) *90)/2) *180)

    sqrt((1)*90) = 9.48

    9.48 / 2 = 4.74

    4.74 * 180 = 853.2

    sin(853.2) = 0.72

    So, starting with 0 we get 0.72 (rather than 1).

    . . . . . . . . . . .

    And if we start with 1 then . . . . . sin((sqrt((1-1) *90)/2) *180)

    sqrt((0)*90) = 0

    0 / 2 = 0

    0 * 180 = 0

    sin(0) = 0

    So, starting with 1 we get 0

    . . . . . . . . . . . .

    So starting with 0 GS gives us 0.72 / 0.99 / 0.09 / 0.99 / 0.35 / -0.59

    So starting with 1 GS gives us 0 (and then we join the above sequence) 0.72 / 0.99 . . etc

    Is this right, or have I missed something obvious ?

    . . . . . .

    EDIT: I think I know where the confusion comes from, were you using an integer for music.volume in your calculation ?

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited October 2015

    @Socks said:
    ... where the confusion comes from ...

    Confusion? I call it pragmatic slight of hand! After all, we are working with, and within the confines of a software program. Well spotted @Socks, I know you didn't have anything better to do tonight. :)

  • SocksSocks London, UK.Member Posts: 12,822

    @Hopscotch said:
    Confusion? I call it pragmatic slight of hand! Well spotted Socks, I know you didn't have anything better to do tonight. :)

    I was planning to wash my attributes, but I won't have time now after uncovering your plot.

    :tongue:

  • Add someAdd some Member Posts: 48

    Thanks guys guys

  • Add someAdd some Member Posts: 48

    Hey guys i have a question very important to me...!

    My game it''s like a levels and this levels isn't visible to player i mean if you click play you will go to level 1 ( you will not see the levels in box 1,2,3... etc )
    Just click play and you will go to level and if you win you will go to level 2 and ...! but the question is i want save levels i mean if you play this game and reached to Level 4 and die you will see in the scene game over the level and the best level reached and when click play again you will play from the level 1 and if you got on a higher level than the previous and die you will see also the level and the best level reached...?

    And if anyone has a video about this will be better to me.

Sign In or Register to comment.