Hi!
I have a working checkbox which activates a function when touched. I was wondering how I would simulate touching the checkbox in the code. I have read a similar topic: Simulating touching screen but I’m not a very experienced programmer and don’t really understand it. If anyone could elaborate and give a bit more of a simple explanation on this topic it would be greatly appreciated.
Here is my code if it helps:
local function musicBtnPressed( event )
local switch = event.target
print( “Sound is on:”…tostring(switch.isOn) )
end
local options = {
width = 100,
height = 100,
numFrames = 2,
sheetContentWidth = 200,
sheetContentHeight = 100
}
local musicButtonSheet = graphics.newImageSheet( “onOffMusic.png”, options )
-- Create a group for the music button
local musicGroup = display.newGroup()
-- Create music button
local musicButton = widget.newSwitch(
{
left = 70,
top = 1870,
style = "checkbox",
id = "MusicButton",
width = 200,
height = 150,
initialSwitchState = true,
onPress = musicBtnPressed,
sheet = musicButtonSheet,
frameOff = 1,
frameOn = 2
}
)
musicGroup:insert(musicButton)
sceneGroup:insert(musicButton)