Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How do I detect music off in individual pages when using scenecontroller? — Gideros Forum

How do I detect music off in individual pages when using scenecontroller?

flyhereflyhere Member
edited March 2014 in Game & application design
I have 5 pages, they are controlled by scenecontroller.

Scenecontroller simply has 3 buttons: go back a page, go forward a page, and a toggle-button for music on/off which works fine for background music on all pages.

self.music:addEventListener("click", self.musicToggle, self)

function sceneController:musicToggle()
if isMusicOn then
isMusicOn = false
bgmusic:stop()
else
isMusicOn = true
bgmusic = bgtune:play(0, true)
end
end


When I'm in a page, I also have other events that will play other sound-effects. I want to have these sounds off or on depending on my musicToggle. I can't use "if isMusicOn" since that is declared in Scenecontroller.

What can I do? I hope I'm making sense.

Thanks

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited March 2014
    I've created a Sounds.lua class just for that purpose:
    https://github.com/ar2rsawseen/GameTemplate/blob/master/classes/Sounds.lua

    Usage is like this:
    --in the main lua
     
    sounds = Sounds.new()
    --adding key and filename
    sounds:add("sound1", "sound1.wav")
    sounds:add("sound2", "sound2.wav")
    sounds:add("sound3", "sound3.wav")
    --etc
     
    --depending on your current setting turn it on
    --sounds:on()
    in your scenes
    --when you need to disable sounds, call
    sounds:off()
     
    --and when need to enable again, call
    sounds:on()
     
    --then when you need to play a sounds, simple call
    sounds:play("sound1")
    --if sounds are on they will play
    --if not, nothing will be played
    Bonus
    --you can add different sounds to same key
    sounds:add("lost", "lost1.wav")
    sounds:add("lost", "lost2.wav")
    sounds:add("lost", "lost3.wav")
     
    --and then when you call play
    sounds:play("lost")
    --it will play one random sound from all provided
  • Thanks, will play with it.
  • @ar2rsawseen,
    you can add a playNext function that will play the next random/queued sound.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • main.lua calls scenecontroller.lua where I have the music toggle right now.

    So I don't put any sound control in scenecontroller? and move the music toggle to main?
  • ar2rsawseenar2rsawseen Maintainer
    @flyhere you can make it a global variable at toggle at any scene you want :)
Sign In or Register to comment.