Hi everyone,
I’ve put some Frankencode together and though it’s not outright crashing, it’s not doing what I want for a global collision listener. I was wondering if someone may be able to help. Physics world setup is in the rest of the code but omitted here.
function newCrate()
rand = math.random( 100 )
if (rand \< 60) then
j = display.newImage("crate.png");
j.x = 60 + math.random( 160 )
j.y = -100
physics.addBody( j, { density=0.9, friction=0.3, bounce=0.3} )
transition.to(self, {time=1000, alpha=0, onComplete=removeBall})
elseif (rand \< 80) then
j = display.newImage("crateB.png");
j.x = 60 + math.random( 160 )
j.y = -100
physics.addBody( j, { density=1.4, friction=0.3, bounce=0.2} )
else
j = display.newImage("crateC.png");
j.x = 60 + math.random( 160 )
j.y = -100
physics.addBody( j, { density=0.3, friction=0.2, bounce=0.5} )
end
end
local function onCollision( self, event )
if ( event.phase == "began" ) then
event.other:removeSelf()
end
end
Runtime:addEventListener( "collision", onCollision )
local dropCrates = timer.performWithDelay( 500, newCrate, 10 )
Thanks for your help. [import]uid: 144359 topic_id: 27207 reply_id: 327207[/import]
(Just go to the Many Crates sample for the image files.)