Hi,
How could I make a mute button which let's me turn the sound back on by clicking it again (it would also be nice if the image would switch when the button is pressed).
Here is my code at current:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | -- Load Background Music 1 media.playSound( 'music1.mp3', true ) -- Music Pause Button local musicbutton = display.newImage( "musicnote1.png" ) musicbutton.x = 965 musicbutton.y = 705 function musicbutton:tap( event ) media.pauseSound( 'music1.mp3' ) end musicbutton:addEventListener( 'tap', musicbutton ) |
*By switch I mean that when the music is muted it swaps to an image of a music note with a red line through it until tapped again (and un-muted).
use some variable like soundIsMute = false and change it to = true then you click on icon
then check if variable is true and with that do another thing in your function...
i hope i explained it simple enough)
I tried:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | -- Load Background Music 1 media.playSound( 'music1.mp3', true ) local SoundPlaying = true local SoundMute = false -- Music Pause Button local musicbutton = display.newImage( "musicnote1.png" ) musicbutton.x = 965 musicbutton.y = 705 function musicbutton:tap( event ) if SoundPlaying = true then media.pauseSound( 'music1.mp3' ) SoundPlaying = false SoundMute = true else media.playSound( 'music1.mp3', true ) SoundPlaying = true SoundMute = false end musicbutton:addEventListener( 'tap', musicbutton ) |
in "if" statements you need to use ==, not single =
lol, thanks darkconsoles. That fixed it ^^
views:1452 update:2011/9/27 8:54:05