So i when my game scene starts a ball is spawned and when i click that ball it disapears and then my function is supposed to start… that function is - a ball spawns and when i click it the ball dissapears… but when i try to remove the ball with display.remove(ball) is gives an error that the ball isnt there… so what im thinking is that the sceneGroup doesnt work in the function? heres the function…
local circle2 = {} local counter2 = 1 local function spawnCircle2(event) if event.phase == "began" then local spawn = math.random(display.contentWidth \* 0.1, display.contentWidth \* 0.9) local spawn2 = math.random(display.contentHeight \* 0.01, display.contentHeight \* 0.99) circle2[counter2] = display.newImageRect( "circle.png", 40, 40 ) circle2[counter2].x = spawn circle2[counter2].y = spawn2 circle2[counter2].value = counter2 counter2 = counter2 + 1 sceneGroup:insert(circle2[counter2]) print("TEST4") end return true end
and when i try to add a event listener like this
circle2:addEventListener("touch", spawnCircle2) BUT Runtime:addEventListener works..
then is says it cant add an event listener to circle2 because its not there…
Any ideas on whats wrong? and what could be fixed? Thanks!