RobertH RobertH - 3 months ago 33
Swift Question

SpriteKit: Getting node at CGPoint

I am new to swift and IOS development in general. I am trying to get the node at a certain point. The only way I can think of getting it would be to save each node into a array and loop through it and check if the position is equal to CGPoint. Is this the best / only way?


Are you trying to get all nodes that intersect with a given CGPoint?

If so, you could simply callnodes(at p: CGPoint) which returns you the list of all nodes which intersects with the point:

let nodes = nodes(at: myPoint)

If your nodes do not overlap, you could use atPoint(_ p: CGPoint) which gets the node with the largest z-order:

let node = atPoint(myPoint)