swift - Two sprites with same categoryBitMask colliding with third sprite -
this code i'm using:
func didbegincontact(contact: skphysicscontact) { var firstbody : skphysicsbody? var secondbody : skphysicsbody? var thirdbody : skphysicsbody? var goodkind : sknode? var badkind : sknode? var bullet : sknode? if (contact.bodya.categorybitmask < contact.bodyb.categorybitmask) { firstbody = contact.bodya secondbody = contact.bodyb goodkind = contact.bodyb.node badkind = contact.bodyb.node bullet = contact.bodya.node } else { firstbody = contact.bodyb secondbody = contact.bodya goodkind = contact.bodya.node badkind = contact.bodya.node bullet = contact.bodyb.node } if (firstbody!.categorybitmask == physicscategory.tooth && secondbody!.categorybitmask == physicscategory.food) { goodkind?.removefromparent() counter++ println("\(counter)") } else if (firstbody!.categorybitmask == physicscategory.tooth && secondbody!.categorybitmask == physicscategory.wrongfood) { badkind?.removefromparent() bullet?.removefromparent() } }
if bullet
collide badkind
badkind
removed bullet fine; if bullet
collide goodkind
goodkind
removed , counter
works fine, if 2 or more bullet
collide goodkind
@ same moment counter
increase 2 or more times. don't want happen can't figure out how make work way want. appreciate help.
Comments
Post a Comment