my friend and i are developing a game with many collisions. right now, we have three objects loaded that respond to collisions differently. there is the zombie, the star, and the happy face. we want it so that when the zombie collides wtih the happy face, the happy face disappears. we got that part working. now what we want is when the happy face touches the star the star diappears. but we are having the problem in which when the star collides with happy, both of them disappear. also when the zombie collides with the happy, happy and the star disappears. any help would be great.
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
– u kinda messed up the one u sent me so spawning in star now and creating its collision properties
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)