Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Mute Entire App
Started by Nathan B Mar 28 2012 03:21 AM

- - - - -
35 replies to this topic
[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

Nathan B

[GLOBAL: userInfoPane.html]
Nathan B
  • Contributor

  • 173 posts
  • Corona SDK

Have you ever used Ice before? I would recommend checking it out if your haven't... http://developer.anscamobile.com/code/ice
I use it for my mute buttons, and it works great.
uid: 39302 topic_id: 24043 reply_id: 106130


[TOPIC: post.html]
#27

se460

[GLOBAL: userInfoPane.html]
se460
  • Contributor

  • 104 posts
  • Corona SDK

Hi Nathan

Thank you for your response. I have tried using ICE, but I think it is a little confusing. :( How have you made your mute button with ICE?

Thank you in advance

uid: 122802 topic_id: 24043 reply_id: 106147


[TOPIC: post.html]
#28

Nathan B

[GLOBAL: userInfoPane.html]
Nathan B
  • Contributor

  • 173 posts
  • Corona SDK

I haven't been doing this that long so this isn't professional advice, but it works for me. :) The stuff below is the setup I have in my app.

In your main.lua file add...

local ice = require("ice")


In the file that your mute button is in add...
local scores = ice:loadBox( "scores" )scores:save()local muteValue = 0--If everything is in your main.lua file, put this under the first thing I said to do.


Then create the button functions...
local mutebuttonfunction = function (event )    if event.phase == "release" then        audio.setVolume( 0.0 ) --this mutes the sound        scores:store("muteValue", 1)        scores:save()    endend    local unmutebuttonfunction = function (event )    if event.phase == "release" then        audio.setVolume( 0.3 ) --this unmutes the sound to the volume I want it        scores:store("muteValue", 0)        scores:save()    endend


Create the buttons... I use widget.newButton
local mutebutton = widget.newButton{        default = "soundon.png",        width = 50,  --I recommend making both buttons the same size        height = 66, --        onRelease = mutebuttonfunction,}mutebutton.isVisible = true     mutebutton.x = 25mutebutton.y = 25        local unmutebutton = widget.newButton{	default = "soundoff.png",        width = 50,         height = 66,        onRelease = unmutebuttonfunction,}    unmutebutton.isVisible = false --you don't want this visible yet    unmutebutton.x = 25  --Make sure its in the same spot as the mutebuttonunmutebutton.y = 25  --


Here's what I do to make them switch when they're pressed...
local unmutebuttonappear = function(event)    if event.phase == "ended" then    	mutebutton.isVisible = false    	unmutebutton.isVisible = true    endend    mutebutton:addEventListener("touch", unmutebuttonappear) --tells the mutebutton to "listen" for a touch, then do the unmutebuttonappear function    local mutebuttonappear = function(event)    if event.phase == "ended" then    	mutebutton.isVisible = true    	unmutebutton.isVisible = false    endend    unmutebutton:addEventListener("touch", mutebuttonappear) --same thing...


Finally, here's the important step to make the app remember if it was muted or unmuted...
if  scores:retrieve("mutevalue") == 1 then    mutebutton.isVisible = false    unmutebutton.isVisible = trueelse    unmutebutton.isVisible = true    unmutebutton.isVisible = falseend

phew... so thats what I do for a stinkin' mute button. :) Feel free to ask more questions!

If anyone else has anything to help me, please let me know. Thanks!

uid: 39302 topic_id: 24043 reply_id: 106207


[TOPIC: post.html]
#29

se460

[GLOBAL: userInfoPane.html]
se460
  • Contributor

  • 104 posts
  • Corona SDK

Hi Nathan

Thank you for the help and the code, much appreciated. I have almost got it to work, I just don't know if I need to place the last code in a function or not? - In general, where have you placed the code?

This code:

if  scores:retrieve("mutevalue") == 1 then    mutebutton.isVisible = false    unmutebutton.isVisible = trueelse    unmutebutton.isVisible = true    unmutebutton.isVisible = falseend


Thank you in advance :)

EDIT: Nevermind, I got it to work - With globals and with ICE :) Thank you
uid: 122802 topic_id: 24043 reply_id: 106284


[TOPIC: post.html]
#30

Nathan B

[GLOBAL: userInfoPane.html]
Nathan B
  • Contributor

  • 173 posts
  • Corona SDK

Great!
uid: 39302 topic_id: 24043 reply_id: 106291


[TOPIC: post.html]
#31

se460

[GLOBAL: userInfoPane.html]
se460
  • Contributor

  • 104 posts
  • Corona SDK

Hi Nathan

To minimize the number of functions, you can move the content of the "button appear functions", into your mute and unmute functions. :) Just thought that it could be usefull, to optimize your app :)


uid: 122802 topic_id: 24043 reply_id: 106337


[TOPIC: post.html]
#32

Nathan B

[GLOBAL: userInfoPane.html]
Nathan B
  • Contributor

  • 173 posts
  • Corona SDK

I've actually tried that, but I get an error. I believe this happens because in the first function, it doesn't know what the unmutebutton is yet. It didn't get that far yet... :)
uid: 39302 topic_id: 24043 reply_id: 106338


[TOPIC: post.html]
#33

se460

[GLOBAL: userInfoPane.html]
se460
  • Contributor

  • 104 posts
  • Corona SDK

Hi

Ohh okay, then you need to declare your buttons on the very top of your module :)
uid: 122802 topic_id: 24043 reply_id: 106376


[TOPIC: post.html]
#34

Nathan B

[GLOBAL: userInfoPane.html]
Nathan B
  • Contributor

  • 173 posts
  • Corona SDK

hmmm. Won't that produce an error also because the function that onRelease calls doesn't exist yet?
uid: 39302 topic_id: 24043 reply_id: 106413


[TOPIC: post.html]
#35

se460

[GLOBAL: userInfoPane.html]
se460
  • Contributor

  • 104 posts
  • Corona SDK

Hi again

No... this is how I have done it :) - I am using globals instead of ICE, but the senario is the same :D

local MusicOfflocal MusicOn local function UnMutePressed ( event )    if event.phase == "release" and MusicOff.isActive then                        Mute = true      audio.setVolume( 1, { channel=1 } )    MusicOn.isVisible = true   MusicOff.isVisible = false endend local function MutePressed ( event )    if event.phase == "release" and MusicOn.isActive then Mute = falseaudio.setVolume( 0, { channel=1 } )   MusicOn.isVisible = falseMusicOff.isVisible = trueendendMusicOn = ui.newButton{    defaultSrc = IMAGE_DIR.."SM2.png",    defaultX = 30,    defaultY = 30,     onEvent = MutePressed	 }	 MusicOn.x = 20; MusicOn.y = 20MusicOn.isVisible = trueMusicOff = ui.newButton{    defaultSrc = IMAGE_DIR.."SM1.png",    defaultX = 30,    defaultY = 30,   onEvent = UnMutePressed	 } MusicOff.x = 20; MusicOff.y = 20MusicOff.isVisible = falseif not Mute then MusicOn.isVisible = false    MusicOff.isVisible = trueelse  MusicOn.isVisible = true   MusicOff.isVisible = falseend


I hope that helps :D
uid: 122802 topic_id: 24043 reply_id: 106428


[TOPIC: post.html]
#36

Nathan B

[GLOBAL: userInfoPane.html]
Nathan B
  • Contributor

  • 173 posts
  • Corona SDK

Sweet! Thanks! -15 lines of code for that button plus whatever I get rid of in other buttons... :)
uid: 39302 topic_id: 24043 reply_id: 106434



[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]