Hi
I’m trying to create an app where you create object and if they are hit with enoungh force they are deleted.
This is my code it works fine exept that it doesn’t delete objects of collision
local physics = require(“physics”)
local gameUI = require(“gameUI”)
physics.start()
physics.setGravity( 0, 0 )
–the sky
local sky = display.newImage( “sky.png” )
–the boundries
–bottom
local ground = display.newImage( “ground.png” )
ground.x = 300
ground.y = 1060
physics.addBody( ground )
ground.bodyType = “static”
–top
local ground4 = display.newImage( “ground.png” )
ground4.x = 300
ground4.y = -40
physics.addBody( ground4 )
ground4.bodyType = “static”
–left side
local ground2 = display.newImage( “ground.png” )
ground2.x = 40
ground2.y = 500
physics.addBody( ground2 )
ground2.bodyType = “static”
ground2.rotation = 90
–right side
local ground3 = display.newImage( “ground.png” )
ground3.x = 720
ground3.y = 500
physics.addBody( ground3 )
ground3.bodyType = “static”
ground3.rotation = 90
local launch = display.newImage( “down.png” )
launch.x = 150
launch.y = 100
local launch2 = display.newImage( “up.png” )
launch2.x = 150
launch2.y = 300
local boxGenerator = display.newImage( “crate.png”, 100, 960 )
local wallmaker = display.newImage( “wall.png”, 125, 760 )
local bird = display.newImage( “bird.png”, 525, 100 )
local function dragBody( event )
gameUI.dragBody( event, { maxForce=20000, frequency=1000, dampingRatio=1.0, center=true } )
end
function moveCircle( event )
local phase = event.phase
if “ended” == phase then
local crate = display.newImage( “crate.png” )
physics.addBody( crate, { density = 5,friction=0.5, bounce=0.3, filter=finish1CollisionFilter } )
crate.x = event.x
crate.y = event.y
crate:addEventListener( “touch”, dragBody )
crate.postCollision = onLocalPostCollision
crate:addEventListener( “postCollision”, crate )
end
end
boxGenerator:addEventListener( “touch”, moveCircle )
function wallMaker( event )
local phase = event.phase
if “ended” == phase then
local wall = display.newImage( “wall.png” )
physics.addBody( wall, { density=3.0, friction=0.5, bounce=0.3 } )
wall.x = event.x
wall.y = event.y
wall:addEventListener( “touch”, dragBody )
end
end
wallmaker:addEventListener( “touch”, wallMaker )
function birdMaker( event )
local phase = event.phase
if “ended” == phase then
local bird = display.newImage( “bird.png” )
physics.addBody( bird, { density=3.0, friction=0.5, bounce=0.3 } )
bird.x = event.x
bird.y = event.y
bird:addEventListener( “touch”, dragBody )
bird:applyForce( -500, 1000, bird.x, bird.y )
localGroup:insert(bird)
end
end
bird:addEventListener( “touch”, birdMaker )
function gravity( event )
local phase = event.phase
if “ended” == phase then
physics.setGravity ( 10, 0 )
end
end
launch:addEventListener( “touch”, gravity )
function gravityup( event )
local phase = event.phase
if “ended” == phase then
physics.setGravity ( -10, 0 )
end
end
launch2:addEventListener( “touch”, gravityup )
local function onLocalPostCollision( self, event )
if ( event.force > 5 ) then
crate:removeSelf()
print( "postCollision force: " … event.force … ", friction: " … event.friction )
end
end
[import]uid: 28068 topic_id: 6290 reply_id: 306290[/import]
[import]uid: 28068 topic_id: 6290 reply_id: 21661[/import]