SKNode convertPoint toNode & fromNode confusion?

后端 未结 4 1874
遇见更好的自我
遇见更好的自我 2020-12-23 10:06

I am a little confused by how the SKNode methods convertPoint:fromNode: and convertPoint:ToNode: are working, I have looked at the doc

4条回答
  •  抹茶落季
    2020-12-23 10:26

    I know this is a late response, but normally, I want to use the node's parent as the coordinate system for the node's position. So, I found this extension to be very useful:

    extension SCNNode {
        func convertPosition(node:SCNNode) -> SCNVector3 {
            return self.convertPosition(node.position, fromNode:node.parentNode)
        }
    }
    

    For example, instead of calling this:

    let position = scene.rootNode.convertPosition(node.position, fromNode: node.parentNode)
    

    you just call this:

    let position = scene.rootNode.convertPosition(node)
    

提交回复
热议问题