Make collision only work with one object.

Haha. I need some serious help here. I failed big time.
There is a cube, and an object to catch it. When the cube hits the object that catches it, I want there to be more cubes.

Also, I’d like for the cube to go away. Help!

Here’s my code.
[lua]local function spawnCrate()
local crate = display.newImage( “cratesmall.png” )
physics.addBody( crate, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate.x = math.random(250)
crate.y = math.random(-40)
end
timer.performWithDelay( 1000, spawnCrate, 2 )

local chute = display.newImage( “chute.png” )
chute.x = display.contentWidth/2
chute.y = 450
physics.addBody( chute, “static”, { friction=0.7 } )

local function onLocalCollision( event )
if ( event.phase == “began” ) then
timer.performWithDelay( 1000, spawnCrate, 1 )

elseif ( event.phase == “ended” ) then
print(“Finish”)
end
end

Runtime:addEventListener( “collision”, onLocalCollision )[/lua] [import]uid: 25216 topic_id: 11695 reply_id: 311695[/import]

Aha! I got it!

Change
[lua]Runtime:addEventListener( “collision”, onLocalCollision )[/lua]
to
[lua]chute:addEventListener( “collision”, onLocalCollision )[/lua]

Thanks! [import]uid: 25216 topic_id: 11695 reply_id: 42528[/import]

Check out Peach Pellen’s Newbie guide part 4 (http://techority.com/2011/06/19/corona-for-newbies-part-4-physics/)

This should work…

[code]
local function spawnCrate()
local crate = display.newImage( “cratesmall.png” )
physics.addBody( crate, { density = 1.0, friction = 0.3, bounce = 0.2 } )
crate.x = math.random(250)
crate.y = math.random(-40)
crate.myName = “crate”
end
timer.performWithDelay( 1000, spawnCrate, 2 )

local chute = display.newImage( “chute.png” )
chute.x = display.contentWidth/2
chute.y = 450
physics.addBody( chute, “static”, { friction=0.7 } )

chute:addEventListener(“collision”, chute)

function chute:collision (event)
if event.other.myName == “crate” then
display.remove( crate )
timer.performWithDelay( 1000, spawnCrate, 1 )
end
end
[/code] [import]uid: 69700 topic_id: 11695 reply_id: 42529[/import]

Ok. Now I only want the top part of the object to work with the collision. Is there an advanced physics body tutorial? [import]uid: 25216 topic_id: 11695 reply_id: 42531[/import]

Ok. Now I only want the top part of the object to work with the collision. Is there an advanced physics body tutorial? [import]uid: 25216 topic_id: 11695 reply_id: 42532[/import]