so a friend and i are trying to make a game where if the zombie collides with the “happy” face, the happy face dissapears. we are having a problem where when the zombie collides with the happy, the star disappears as well. also, when the happy touches the star, both disappear. we want it so that only the star disappears when happy collides with it and when the zombie collides with happy only happy disappears, here is all the collision code –
function onCollision(event)
–print(“collide!”)
happy:removeSelf()
end
Runtime:addEventListener(“collision”, onCollision)
local function onCollision2( self, event )
if ( event.phase == “began” ) then
– Check if body still exists before removing
if( happy) then
happy:removeSelf()
happy = nil
end
end
end
local star = display.newImage( “starsmall.jpg” )
star.x = 400
star.y = 100
physics.addBody(star, “static”)
star.collType = “none”
physics.addBody( star, { bounce=10.0, friction=1.0 } )
function movestar()
transition.to(star,{time=900, x=math.random(300,500), y=math.random(0,200), onComplete=movestar})
end
movestar()
function onCollision(event)
–print(“collide!”)
star:removeSelf()
end
Runtime:addEventListener(“collision”, onCollision)