Hi, in my game i have created a collision function, in this game multiple eggs fall from the sky and when they collide with the “ground” i want them to disappear … the problem is that when the first contacts the ground it disappears but the rest of them don’t… can you pls help me?
COLLISON CODE:
function onGroundCollision( self, event )
if ( event.phase == “began” ) then
if(self.myName == “egg”) then
if(event.other.myName == “ground”) then
audio.play(sound3)
self.isVisible = false
self:removeSelf()
end
end
end
end
FRAMES CODE:
this is the code that drops multiple eggs
ocal function onFrame(event)
frameCounter = frameCounter + 1
if(frameCounter % 40 == 0 and eggCount > 0) then
eggCount = eggCount - 1
local egg = display.newImage(“egg.png”)
egg.x = math.random(0, 310)
egg.y = 0
egg.rotation = math.random(0, 360)
physics.addBody(egg, {density = 2.0, friction = 1.5, bounce=0.01})
Hi Abraham,
Where do you set the “myName” property on the eggs? Or on the ground object?
Brent
Hi Brent
I set “myName” property on the egg in the “createScene” section .. e.g
egg = display.newImage(“egg.png”)
egg.x = 180
egg.y = 80
egg.rotation = 10
physics.addBody(egg, {density = 2.0, friction = 1.5, bounce=0.0})
egg.myName = “egg”
screenGroup:insert( egg )
OK, I see. You need to apply this property to each egg that you generate in the loop. Each “local” egg is a new display object, so it has its own properties that it doesn’t inherit from anywhere else. Thus, you need to add this to every new egg. That should do the trick. 
Brent
Hi Abraham,
Where do you set the “myName” property on the eggs? Or on the ground object?
Brent
Hi Brent
I set “myName” property on the egg in the “createScene” section .. e.g
egg = display.newImage(“egg.png”)
egg.x = 180
egg.y = 80
egg.rotation = 10
physics.addBody(egg, {density = 2.0, friction = 1.5, bounce=0.0})
egg.myName = “egg”
screenGroup:insert( egg )
OK, I see. You need to apply this property to each egg that you generate in the loop. Each “local” egg is a new display object, so it has its own properties that it doesn’t inherit from anywhere else. Thus, you need to add this to every new egg. That should do the trick. 
Brent