android - Add sound switch off/on button corona sdk -


i need adding sound off/on button game. in global variable lua file, have following:

local sounds = {} sounds["select"] = audio.loadsound("sounds/select.mp3") sounds["score"] = audio.loadsound("sounds/score.mp3") g.playsound = function(name)      if sounds[name] ~= nil          audio.play(sounds[name])     end end 

in games.lua file, call function as:

utils.playsound("score") 

i have soundon.png , soundoff.png files both in sprite sheet (not sure if idea), trying implement when click sound button, sounds stops , displays soundoff image, vice versa. thanks

i wouldn't use sprite sheet. load both images , toggle "isvisible" field. toggle variable stop sounds. try this.

myglobalsoundtoggle = true local image = display.newimage("soundon.png") local image2 = display.newimage("soundoff.png") image2.isvisible = false  local function ontap( self, event )     image.isvisible = ~image.isvisible     image2.isvisible = ~image2.isvisible     myglobalsoundtoggle = image.isvisible     return true end  image:addeventlistener( "tap", ontap ) 

now have our buttons working, need toggle sound on , off.

local sounds = {} sounds["select"] = audio.loadsound("sounds/select.mp3") sounds["score"] = audio.loadsound("sounds/score.mp3") g.playsound = function(name)      if (sounds[name] ~= nil) , (myglobalsoundtoggle)          audio.play(sounds[name])     end end 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -