SpriteKit:检测旋转节点的重叠?

时间:2023-01-22 21:21:08

Assume nodeA is a child of nodeB. Changing the value of zRotation for nodeB effectively rotates nodeA, but nodeA's position (since it's relative to nodeB) remains the same.

假设nodeA是nodeB的孩子。改变nodeB的zrotate的值可以有效地旋转nodeA,但是nodeA的位置(因为它是相对于nodeB的)保持不变。

Now assume nodeA is removed from nodeB, but its position remains fixed in the screen. nodeC is added to nodeB and rotated.

现在假设nodeA从nodeB中移除,但是它的位置仍然固定在屏幕上。nodeC被添加到nodeB并被旋转。

How can you detect overlap between nodeC and nodeA? containsPoint in SKNode, as described here, doesn't work since both nodeC and nodeA positions never change due to rotation.

如何检测nodeC和nodeA之间的重叠?如本文所述,SKNode中的containsPoint不工作,因为nodeC和nodeA的位置都不会因为旋转而改变。

1 个解决方案

#1


2  

You can tests nodes intersection with - (BOOL)intersectsNode:(SKNode *)node. But in this case nodes need to be in same node tree. Maybe you should not remove nodeA from nodeB before test?

您可以测试与- (BOOL)intersectsNode:(SKNode *)节点相交的节点。但在这种情况下,节点需要位于相同的节点树中。也许你不应该在测试前将nodeA从nodeB中移除?

#1


2  

You can tests nodes intersection with - (BOOL)intersectsNode:(SKNode *)node. But in this case nodes need to be in same node tree. Maybe you should not remove nodeA from nodeB before test?

您可以测试与- (BOOL)intersectsNode:(SKNode *)节点相交的节点。但在这种情况下,节点需要位于相同的节点树中。也许你不应该在测试前将nodeA从nodeB中移除?