This is my first attempt at programming and I’m fairly stuck. I have a simple game that has objects falling down the screen and when you press a button that corresponds to the lowest object, it removes it. It was working fine until I added the spawned objects to the sceneGroup. Now the objects stay visible after the correct button is pressed.
Here’s the function I use to match the button press to the next table object:
local function buttonHandler( event ) if (spawnTable[1] ~= nil) then if (event.phase == "began" and spawnTable[1].y \> 0 - spawnTable[1].contentHeight/2) then if (spawnTable[1].myName == event.target.id) then display.getCurrentStage():remove(spawnTable[1]) table.remove(spawnTable, 1) score = score + 1 audio.play(blop) else composer.gotoScene("gameOver") end end else composer.gotoScene("gameOver") end end
And here’s where I add the spawned object to the sceneGroup:
for i=1, numOfBirds, 1 do spawnTable[i] = spawnBird({count=i, offSet = 50}) physics.addBody(spawnTable[i]) spawnTable[i]:setLinearVelocity( 0 , velocity ) sceneGroup:insert( spawnTable[i] ) end
Without adding the spawned objects to the sceneGroup, the objects are removed when the correct button is pressed, but they stay on the screen between scenes, but adding the objects to the sceneGroup stop me from being able to remove them with the buttons.