I have a function to create a box where the user clicks, and when the user clicks on that same box I want it to be removed from the display. My problem is the box gets removed and then created again because the two events are happening one after another.
I have the createBox function bound to the “tap” event on the background and the “tap” event on the box bound to an anonymous function that removes the box.
I’m pretty new to corona, suggestions on how to best handle this is much appreciated!
local width = 100 local physics = require("physics") physics.start() uiGroup = display.newGroup() background = display.newRect(uiGroup, display.contentCenterX, display.contentCenterY, display.contentWidth, display.actualContentHeight) background:setFillColor(1,0,0) background.alpha = 1 background.isHitTestable = true background:toBack() local function createBox(event) little\_rect = display.newRect(uiGroup, event.x, event.y, width/4, width/4) physics.addBody(little\_rect, "static") print("created box") little\_rect:addEventListener("tap", function(event) print("removed box") display.remove(little\_rect) end) end background:addEventListener("tap", createBox)