detect contact when both physics bodies are dynamic sprite kit objective c

蓝咒 提交于 2019-12-12 03:59:25

问题


is it possible to detect a contact and let the object pass the other ? Because I want to increase a variable when they pass each other.

I made both phyisicsbodies dynamic, then they pass but didBeginContact is not working anymore then.

Thanks

EDIT:

Okay , so everything is working when I don't have the bodies dynamic. I have a BottomEdgeBody which I use to detect when the raining stones passed my player and then it increases the Score. So, if nothing is dynamic, my stones stay on top of the bottomEdge but I want them to fall through it.

Some Code:

in didBeginContact

if(contact.bodyA.categoryBitMask == bottomEdgeCategory)
{
    self.scoring = self.scoring +1;
    [self.scoreLabel setText:[NSString stringWithFormat:@"Score: %ld", (long)self.scoring]];
}
if(contact.bodyB.categoryBitMask == bottomEdgeCategory)
{
    self.scoring = self.scoring +1;
    [self.scoreLabel setText:[NSString stringWithFormat:@"Score: %ld", (long)self.scoring]];

}

If i make stone.physicsBody.dynamic = NO; and same for the bottomEdge, they pass themselves but the score is not increased anymore.


回答1:


Okay thank you, I just settled the collision Bit mask of the Stone and the BottomEdge to 0, then it is working properly



来源:https://stackoverflow.com/questions/32610258/detect-contact-when-both-physics-bodies-are-dynamic-sprite-kit-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!