Another way, which may be better suited is to have an array that represents each 12 position. Each array entry is another table of information, including the X, Y locations of the spots and other information. It would also hold each items display object that you could create based on which mole is showing up, set additional properties for that mole etc. Then on tap, you would just remove the mole using removeSelf() and set the entry in the table to nil for garbage collection. But the table would still be holding the X, Y locations.
Then you could do a simple for loop to run through the 12 spots and see if all of the display entries are nil, if so create your new mole.
local hole = {}
hole[1].x = 100
hole[1].y = 100
hole[1].mole = nil
hole[2].x = 100
hole[2].y = 100
hole[2].mole = nil
-- etc.
local function whackMyMole(event)
if event.phase == "began" then
slot = event.target.index
hole[slot].mole:removeSelf()
hole[slot].mole = nil
end
end
local function spawnMole()
local haveMole = false
for i = 1, 12, do
if hole[i].mole then haveMole = true end
end
if not haveMole then
local whichHole = math.random(12)
hole[whichHole].mole = display.newImageRect("mymole.png", 64, 64)
-- plus whatever you need to do, add to a group, etc.
hole[whichHole].mole:addEventListener("touch",whackMyMole)
hole[whichHole].mole.index = whichHole
end
end
Or something like that… [import]uid: 19626 topic_id: 28096 reply_id: 113533[/import]