Why won’t the robot objects collide with the line?
[lua]physics = require( “physics” )
physics.start()
physics.setGravity( 0, 9 )
—[[
physics.setDrawMode( “hybrid” )
–]]
level = 1
local lineFilter = { categoryBits = 2, maskBits = 1 }
display.setStatusBar(display.HiddenStatusBar)
local screenW = display.contentWidth
local screenH = display.contentHeight
local background = display.newRect(0,0, screenW,screenH)
background:setFillColor(200,255,200)
local lowtoucharea = display.newRect(0,screenH*0.9,screenW,screenH*0.1)
local hightoucharea = display.newRect(0,screenH*0.8,screenW,screenH*0.1)
hightoucharea:setFillColor(255,0,0)
function makerobot()
local robot =display.newImageRect(“robot”…math.random(1,2)…".png", 306,210)
robot.x = math.random(0,screenW*.9)
robot.y = 500–math.random(-500,-100)
local scaleFactor = 1.0
local physicsData = (require “robot”).physicsData(scaleFactor)
physics.addBody( robot, physicsData:get(“robot”) )
robot:applyAngularImpulse(math.random(-360,360))
–transition.to(robot, {time = math.random(9000/level,15000), y= screenH+500, onComplete = function(self) self.parent:remove(self); self = nil; end })
timer.performWithDelay(1000,makerobot)
end
makerobot()
function highdrawLine( event )
if(event.phase == “ended”) then
box = display.newRect(eventx,eventy,1000,10)
box:setFillColor(255,0,0)
box:setReferencePoint( display.TopLeftReferencePoint )
box.rotation = 90+math.floor(180-math.atan2(eventx - event.x, eventy - event.y)*(180/math.pi))
transition.to(box, {time = 1000, alpha=0, onComplete = function(self) self.parent:remove(self); self = nil; end })
physics.addBody(box, “static”, {filter = lineFilter})
– line = display.newLine(event.xStart, event.yStart, event.x, event.y)
–[[ line = display.newLine(eventx, eventy, event.x,event.y)
line:setColor(255,0,0)
line.width = 10
transition.to(line, {time = 1000, alpha=0, onComplete = function(self) self.parent:remove(self); self = nil; end })
– physics.addBody(line, “static”) --]]
eventx = nil
eventy = nil
end
end
function lowdrawLine( event )
if(event.phase == “began”) then
eventx = event.x
eventy = event.y + 100
end
end
hightoucharea:addEventListener(“touch”, highdrawLine)
lowtoucharea:addEventListener(“touch”, lowdrawLine)[/lua]
robots filter:
[lua] filter = {categoryBits = 1, maskBits = 2},[/lua] [import]uid: 79135 topic_id: 15278 reply_id: 315278[/import]
[import]uid: 79135 topic_id: 15278 reply_id: 56513[/import]