[code]
local physics = require ‘physics’
physics.start()
physics.setGravity( 0, 9.8 )
local circle1 = display.newCircle( 100,100, 5 ) ball2
circle1.myName = “circle1”
circle1.x = 50
local circle2 = display.newCircle(100,100,5) — ball1
circle2.myName = “circle2”
local rect = display.newRect( 0,0 , 100,10 ) – flag
rect.x = 200
rect.y = 450
rect.rotation = 90
rect.myName = “rect”
local rect2 = display.newRect( 0,0 , 300,10 )
rect2.y = 450
rect2.rotation = 20
rect2.myName = “rect2”
physics.addBody( circle1, “dynamic”, {friction=0, bounce=0, density=0 } )
physics.addBody( circle2, “dynamic”, {friction=0, bounce=0, density=0 } )
physics.addBody( rect, “kinematic”, {friction=1, bounce=.2, density=1 } )
physics.addBody( rect2, “static”, {friction=1, bounce=.2, density=1 } )
circle2:addEventListener(“collision”, circle2) — attach collision listener to the object ball1
function circle2:collision (event)
if event.other.myName == “rect” then
–do what ever you what to do
– rect:removeSelf()
end
–[[
you can add as many if statement as you want
if event.other.myName == “rect2” then
–do what ever you what to do
– rect:removeSelf()
end
–]]
end
Please read the physics documentation section.
Diginutscorp@gmail.com
twitter @diginutscorp
[import]uid: 40990 topic_id: 21423 reply_id: 84869[/import]