Collision problem

Hey guys,

So I made like spawner which spawn lasers every 1s. I want to delete the laser which touch the line but the problem is I get nil value when I want to add listener at enter scene. I managed to fix that nil value but thing i want to do still doesn’t work.

EDIT : Event listener is not added to upcoming laser beams so spawned lasers stay on line instead of being deleted. How to fix this?

above create scene

oncheck = 0 local goPress = function( event ) check = check + 1 end

function onLocalCollision2( laserbeam1, event )

       if ( event.other.myName == “line” ) then

          laserbeam1:removeSelf()     

        end

end

local goPress = function( event )

check = check + 1

timer.resume(lasertmr)

physics.addBody(billy,“dynamic”,{density=1, bounce=0.5, friction=1.0, radius=27})

physics.start()

circle:removeEventListener( “touch”, circle )

rotate:removeEventListener(“touch”, rotateObj)

circle:removeEventListener(“touch”, onTouch)

rotator:removeEventListener(“touch”, rotatorObj)

line1:removeEventListener(“touch”, onTouchR)

line1:removeEventListener(“touch”)

line2:removeEventListener( “touch”, line2 )

krotator:removeEventListener(“touch”, krotatorObj)

line2:removeEventListener(“touch”, onTouchK)

line3:removeEventListener( “touch”, line3 )

l3krotator:removeEventListener(“touch”, l3krotatorObj)

line3:removeEventListener(“touch”, onTouchl3)

line4:removeEventListener( “touch”, line4 )

l4krotator:removeEventListener(“touch”, l4krotatorObj)

line4:removeEventListener(“touch”, onTouchl4)

end

Create scene

function laserSpawner() laserbeam1 = display.newImage("laserbeam.png") laserbeam1.x = 200 laserbeam1.y = 44 laserbeam1.isVisible = true laserbeam1.rotation = 90 laserbeam1.myName = "laser" physics.addBody(laserbeam1,"dynamic",element) screenGroup:insert(laserbeam1) end lasertmr = timer.performWithDelay( 1000, laserSpawner, 0 ) timer.pause(lasertmr) if ( oncheck == 0 ) then laserbeam1 = display.newImage("laserbeam.png") -- this laser get's deleted laserbeam1.x = 200 when it touches line but this laser laserbeam1.y = 44 is just here to prevent nil value laserbeam1.rotation = 90 from happening so I think it only laserbeam1.myName = "laser" adds listener to this laser not to screenGroup:insert(laserbeam1) one from laser spawner function physics.addBody( laserbeam1, "dynamic" , element ) oncheck = oncheck + 1 elseif ( oncheck == 1 ) then lasertmr = timer.performWithDelay( 1000, laserSpawner, 0 ) timer.pause(lasertmr) end

Enter scene

circle:addEventListener( "touch", circle ) rotate:addEventListener("touch", rotateObj) circle:addEventListener("touch", onTouch) line1:addEventListener( "touch", line1 ) rotator:addEventListener("touch", rotatorObj) line1:addEventListener("touch", onTouchR) line2:addEventListener( "touch", line2 ) krotator:addEventListener("touch", krotatorObj) line2:addEventListener("touch", onTouchK) line3:addEventListener( "touch", line3 ) l3krotator:addEventListener("touch", l3krotatorObj) line3:addEventListener("touch", onTouchl3) line4:addEventListener( "touch", line4 ) l4krotator:addEventListener("touch", l4krotatorObj) line4:addEventListener("touch", onTouchl4) line1t:addEventListener( "tap", onLineTouch ) lineMediumT:addEventListener( "tap", onMediumLineTouch ) billy.collision = onLocalCollision billy:addEventListener( "collision", billy ) boxl2.collision = onLocalCollision boxl2:addEventListener( "collision", boxl2 ) boxl3.collision = onLocalCollision boxl3:addEventListener( "collision", boxl3 ) --- from here it's what you should look at laserbeam1.collision = onLocalCollision2 laserbeam1:addEventListener( "collision", laserbeam1 ) line1.collision = onLocalCollision2 line1:addEventListener( "collision", line1 ) line2.collision = onLocalCollision2 line2:addEventListener( "collision", line2 ) line3.collision = onLocalCollision2 line3:addEventListener( "collision", line3 ) line4.collision = onLocalCollision2 line4:addEventListener( "collision", line4 ) circle.collision = onLocalCollision2 circle:addEventListener( "collision", circle )

If anyone has idea how to make laser spawner which starts to spawn lasers when I click Go button and those lasers get deleted when they collide with line. Thanks!

Please anyone? Really need this to continue working on my project.

Please anyone? Really need this to continue working on my project.