ios - Why is SKNode nodeAtPoint returning wrong node? -
apples docs state nodeatpoint method on sknode returns deepest node in tree. take mean if draw out tree scene node @ top, answer should expected 1 of nodes @ bottom-most position in tree. isn't happening me. here's tree looks like:
scene | world | +------------+----+---------+------------+ | | | | leftarrow rightarrow boardlayer statuslayer | +-----------+-----------+--------+-+---------------+ | | | | | arrow highlight trough rotating(0) testdump (21) | +--------+----------+ | | | guides board playerpiece (24) (20) (13)
the numbers in parens z-position of nodes. when ask scene for "nodesatpoint" , give calculated point corresponding location of playerpiece get: "world, boardlayer, rotating, highlight, board, playerpiece". expect. when query scene "nodeatpoint" using same point "highlight". expected playerpiece. why didn't node returned? overlooking?
i'm not sure code here is. code in board.m (bottom of tree).
cgpoint pt = [checkerutilities locationfromcolumn:column row:row]; cgpoint p = [self.parent.parent convertpoint:pt tonode:[globals sharedglobals].scene]; nsarray *nodes = [[globals sharedglobals].scene nodesatpoint:p]; (sknode *node in nodes) nslog(@"%@, %@, %f", [node class], node.name, node.zposition); sknode *checker = [[globals sharedglobals].scene nodeatpoint:p]; nslog(@"node: %@", [checker class]);
the output is:
sknode, world, 0.000000 boardlayer, boardlayer, 0.000000 skspritenode, rotating, 0.000000 highlight, highlight, 21.000000 board, board, 20.000000 checkersprite, checker, 13.000000 node: highlight
from docs:
in scene, when sprite kit processes touch or mouse events, walks scene find closest node wants accept event. if node doesn’t want event, sprite kit checks next closest node, , on. the order in hit-testing processed reverse of drawing order.
in other words, hit testing starts last child added node first (as stated). however, zposition not overrides draw order hit-test order:
sprite kit uses zposition value determine hit testing , drawing order.
the node highest z value selected first if multiple nodes overlap @ tap point.
Comments
Post a Comment