Search code examples
iosobjective-cswiftsprite-kitsknode

Is the order of SKNode.nodesAtPoint guaranteed?


SKNode has a method nodesAtPoint which returns an array of children nodes that intersect given point. Is the order of the elements in such array deterministic (e.g. by drawing order)?

I could not find an answer in documentation, so probably the answer is "no", but I would like to verify.


Solution

  • Nope, Sprite Kit does not take into account z-position when traversing the node-tree (definitely for performance reasons). You can easily see this by adding a few nodes to a scene in-order and then changing the z-positions. The order will always be based on the position of the node within the node-tree, rather than the z-position.