Error - the hit test does not work as intended when the brothers and sisters overlap:
There are 2 overlapping nodes in the scene that have the same parent element (i.e. siblings)
The topmost node has userInteractionEnabled = NO , and the other node has userInteractionEnabled = YES .
If the overlap is affected, after the highest node is checked with an error and does not work (because userInteractionEnabled = NO ), instead of the lower node following after testing, it is skipped, and the parent of 2 siblings is checked for impact.
What should happen is that the next sibling (lower node) is being tested with an error, and does not fall into the parent hit-test tag.
According to the Sprite Kit documentation:
“In the scene, when the Sprite Kit processes touch or mouse events, it looks through the scene to find the nearest node that wants to receive the event. If this node does not want the event, the Sprite Kit checks the next nearest node and therefore on. The order of processing hit tests "This is essentially the reverse order of drawing. For a node that should be considered during impact testing, its userInteractionEnabled property must be set to YES. The default value is NO for any node except the node scene."
This is a mistake when the brothers and sisters from node face their parents - this should be the next brother, not his parent. In addition, if the node has userInteractionEnabled = NO , then of course it should be transparent with respect to impact testing - but here it is not the way it leads to a change in behavior when the node test misses.
I searched on the Internet but cannot find anyone and messages or messages about this error. So should I report this?
And then the reason why I posted it here is because I would like to suggest a “fix” for this error (that is, a proposal to implement some code somewhere so that SpriteKit works in the “intended” manner for impact testing)
To reproduce the error:
Use the "Hello World" template provided when you launch the new Game project in Xcode (it has a "Hello World" and adds rocket sprites when you click).
Optional: [I also deleted the image of the raster sprite from the project, since the rectangle with X , which occurs when the image is not found, is easier to work with for debugging, visually]
Add SKSpriteNode to the scene using userInteractionEnabled = YES (now I will call it node A).
Run the code.
You will notice that when you press node A, no rocket sprites are generated. (expected behavior, since the bit test should stop after it succeeds - it stops when it succeeds in node A.)
However, if you create several rockets that are next to node A, and then click on the place where node A and the rocket overlap, then you can create another rocket on top of node A - but this should not be possible. This means that after the test failure fails on the topmost node (rocket with userInteractionEnabled = NO by default), instead of testing node A next, it instead checks the rocket's parent, namely Scene.
Note. I am using Xcode 7.3.1, Swift, iOS. I have not tested yet whether this error is universal.
Additional information: I did some additional debugging (a little complication for replication above) and determined that the hit test is then sent to parents and, therefore, not necessarily to the stage.