Hi Everyone,
So I’ve built TWO widget.newSlider() as toggle buttons to adjust the volume up and down.
Individually, they work fine.
The first is to control the background music (Channel = 1)
The other to control all sound effects volume (Channel = 2)
The problem is they both fire an event, which is then effecting both widgets.
As they are widgets, the event() is not able to event.target.name.
I’ve tried if statements to identify which channel is which event, using this…
audio.getVolume( channel=1)
but no luck.
How do I separate the logic of the event, so I can determine which widgets function responds?
btnSliderMusic = widget.newSlider( {
sheet = graphics.newImageSheet( "Buttons/widgetBtnSlider.png", modAdmin.btnSliderOptions ),
leftFrame = 1,
middleFrame = 2,
rightFrame = 3,
fillFrame = 4,
frameWidth = 18,
frameHeight = 32,
handleFrame = 5,
handleWidth = 32,
handleHeight = 32,
x = display.contentCenterX,
y = display.contentCenterY,
orientation = "horizontal",
width = 250,
value = musicVolumeIn,
listener = adjustMusicVolume
}
)
btnSliderMusic.name = "btnSliderMusic"
btnSliderSFX = widget.newSlider( {
sheet = graphics.newImageSheet( "Buttons/widgetBtnSlider.png", modAdmin.btnSliderOptions ),
leftFrame = 1,
middleFrame = 2,
rightFrame = 3,
fillFrame = 4,
frameWidth = 18,
frameHeight = 32,
handleFrame = 5,
handleWidth = 32,
handleHeight = 32,
x = display.contentCenterX,
y = display.contentCenterY,
orientation = "horizontal",
width = 250,
value = musicSFXIn,
listener = adjustSFXVolume
}
)
local function adjustMusicVolume( event )
print("adjustMusicVolume event.name: "..event.name)
if ( event.phase == "began" ) then
display.getCurrentStage():setFocus( event.target )
event.target.isFocus = true
lblMusicVolume.text = "Music Volume: " .. event.value .. "%"
setVolumeMusic = event.value/100 -- devide value by 100 to get a 0. number
audio.setVolume( setVolumeMusic, { channel=1 } ) -- dedicated channel control
elseif ( event.phase == "ended" or event.phase == "cancelled" ) then
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
end
end
local function adjustSFXVolume( event )
print("adjustSFXVolume event.name: "..event.name)
if ( event.phase == "began" ) then
display.getCurrentStage():setFocus( event.target )
event.target.isFocus = true
lblMusicSFX.text = "SFX Volume: " .. event.value .. "%"
setVolumeSFX = event.value/100 -- devide value by 100 to get a 0. number
audio.setVolume( setVolumeSFX, { channel=2 } ) -- all channels remaining
elseif ( event.phase == "ended" or event.phase == "cancelled" ) then
display.getCurrentStage():setFocus( nil )
event.target.isFocus = false
end
end
Thanks