Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...