2

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.

0x416e746f6e
  • 9,872
  • 5
  • 40
  • 68

1 Answers1

1

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.

Epic Byte
  • 33,840
  • 12
  • 45
  • 93
  • Thanks. I did some better tests myself, and it seems that the order is not always there at all. – 0x416e746f6e Jul 06 '15 at 18:14
  • @AntonBronnikov Yup, and if you have nodes with children it gets even more unpredictable. – Epic Byte Jul 06 '15 at 18:15
  • Which means that there's some hash-table probably being used under the water, some dictionary I guess. At any rate, I think have to do sorting on the result array. – 0x416e746f6e Jul 06 '15 at 18:18