So ok this is the most simple program ever and I’m having issues with it lol. I just made a background and a button that when clicked the score increase 1 so I can work with saving scores and etc with just code. Ive never had this happen before but when I click on the button image the background is also clicked and Im not sure why. The background event listener listens for a different function than the button listener so I’m not sure why the background is also picking up the button one.
[lua]display.setStatusBar(display.HiddenStatusBar)
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()
local mydata = require(“mydata”)
score = 0
function scene:createScene(event)
local sceneGroup = self.view
local background = display.newRect(display.contentCenterX, display.contentCenterY, 700,1200)
background:setFillColor(1,1,1)
sceneGroup:insert(background)
local button = display.newImageRect(“start.png”,400,200)
button.x = display.contentCenterX
button.y = display.contentCenterY
sceneGroup:insert(button)
background:addEventListener(“touch”,missed)
button:addEventListener(“touch”,clicked)
end
function missed(event)
if event.phase == “began” then
print(“you missed”)
score = 0
print(“score reset to 0”)
end
end
function clicked(event)
if event.phase == “began” then
score = score + 1
print(score)
end
end
function scene:enterScene(event)
end
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“createScene”,scene)
return scene[/lua]