且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ios - Spritekit - 如何计算两个节点之间的距离?

更新时间:2021-11-14 23:06:53

这是一个能为你做的功能。这来自Apple的Adventure示例代码:

Here's a function that will do it for you. This is from an Apple's Adventure example code:

CGFloat SDistanceBetweenPoints(CGPoint first, CGPoint second) {
    return hypotf(second.x - first.x, second.y - first.y);
}

要从您的代码中调用此函数:

To call this function from your code:

CGFloat distance = SDistanceBetweenPoints(nodeA.position, nodeB.position);