So I am trying to make two non physics objects interact with each other,but I’m doing something bad somewhere.
The console still prints “works” even when obj.y is different than beam.y-90. Here’s the code.
local ufo = display.newImageRect("ufo2.png" ,100,90) ufo.x = 100 ufo.y = 100 local beam = display.newImageRect("Beam.png" ,90,200) beam.isVisible = false local obj = display.newImageRect ("Icon.png",70,70) obj.x = 100 obj.y = 300 local sheetData = {width = 100,height = 90,numFrames = 8,sheetContentWidth = 200,sheetContentHeight = 360} local mySheet = graphics.newImageSheet ("ufo.png",sheetData) local sequenceData = {name = "ufo1",start = 1,count = 8,time = 950,loopcount = 0,looDirection = "forward"} local ufo1 = display.newSprite (mySheet,sequenceData) ufo1.x = 150 ufo1.y = 200 ufo1.isVisible = false function beamOn (event) if event.phase == "began" then beam.isVisible = true beam.x = ufo.x beam.y = ufo.y + 110 if beam.x \< 50 then beam.isVisible = false end end end ufo:addEventListener ("touch",beamOn) function beamOff (event) if event.phase == "ended" then beam.isVisible = false end end ufo:addEventListener ("touch",beamOff) function roads (event) if obj.x \< - 10 then obj.x = 300 else obj.x = obj.x - 1 end end Runtime:addEventListener ("enterFrame",roads) function onCollision( event ) if event.phase == "began" then if beam.y == obj.y - 90 then print("works") end elseif event.phase == "ended" then print("worked") end return true end Runtime:addEventListener ("touch",onCollision)
I also tried to look up at the Non physics collision detection tutorial,but I haven’t understand anything.Maybe some other examples…