我有两个 SKShapeNodes——一个基于边缘的 SKPhysicsBody,一个基于体积——我想在没有碰撞的情况下检测它们的交点。我的这个工作正常,SKPhysicsContactDelegate 接触方法在一个人经过另一个时被调用,但我的问题是当边缘不再相交时,didEndContact 被调用,即使一个物体完全包含在另一个物体中。确定真正接触或重叠的最佳方法是什么,而不仅仅是边缘相交?我试过 usesPreciseCollisionDetection ,但无济于事。

最佳答案

CGPoint locObj1 = [sprite1 locationInNode:self];
CGPoint locObj2 = [sprite2 locationInNode:self];

if([sprite1 containsPoint: locObj2]) return;
if([sprite2 containsPoint: locObj1]) return;

将此添加到 didBeginContact 和 didEndContact 的开头。这会检查其中一个节点是否包含另一个节点。如果是这样,它不会做任何事情来缓解您的 didBeginContact 和 didEndContact 被不必要地调用的问题。我不在我的 mac 上,所以你可能需要稍微玩一下语法。希望这能让你朝着正确的方向前进。

关于ios - SpriteKit : detect complete node overlap,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24412487/

10-13 03:50