2 Replies
      Latest reply on Jul 24, 2019 12:36 AM by Sungwook
      Sungwook Level 1 Level 1 (0 points)

        Seeing the explanation "Compares the parameter node to the receiving node." and the name of function, it sounds like " comparing the receiver with the parameter node".

        However, "true if the node is a descendant of the parent node; otherwise false." down the description gives me different thought about it that it exists to check if the parameter node is a child node of the receiver.

         

        I couldn't get it right just by seeing the explanation: it is not clear.

         

        Here it goes the link I'm refer to

        https://developer.apple.com/documentation/spritekit/sknode/1483078-isequal

         

        I'm very confused at the description isEqual(to node: SKNode) -> Bool

        Do anyone give me a clear explanation about this?

         

        Thanks in advance.

        • Re: How to use SKNode's isEqual(to:) function? confusing.
          gchiste Apple Staff Apple Staff (200 points)

          The SKNode header file states that isEqual(to:) "Returns true if this node has equivalent content to the other object, otherwise false".

           

          Here is an example:

           

                  let node1 = SKNode()

                  self.addChild(node1)

                  node1.name = "node"

           

                  let node2 = SKNode()

                  node2.name = "node"

           

                  let node3 = SKNode()

                  node3.name = "differentNode"

                  self.addChild(node3)

               

                  print(node1.isEqual(to: node2)) // true (even though the nodes have different parents, they have the same content, so this is true)

                  print(node1.isEqual(to: node3)) // false (even though the nodes have the same parents, they have different content, so this is false)

                  print(node2.isEqual(to: node3)) // false (the nodes have different parents and different content, so this is false)

           

          As you can see from this example, the content of the node is the important differentiator when using isEqual(to:).