Tag: zposition

在SpriteKit中,zPosition如何用于渲染和命中testing?

编辑:苹果公司在iOS8中解决了这个问题,所以这肯定不是预期的,而是一个错误。 看起来zPosition在用于渲染节点时与在用于确定哪个节点被触摸时的解释是不同的。 当我创build父节点和子节点的层次结构(全部使用zPosition集合)时,渲染的最顶层节点由通向节点的所有zPositions的总和决定,因此来自不同父节点的节点可以交错。 但是,当确定接收触摸的最顶层节点时,zPosition仅用于区分同一父节点的同胞,当节点具有不同的父节点时,其父节点z顺序优先。 (一个父母的所有孩子都在一个不同的父母的节点之下或之上) 为了说明,一些带有结果的示例代码: #import "MyScene.h" @interface NodeWithHitTest : SKSpriteNode -(instancetype)initWithColor:(UIColor *)color size:(CGSize)size; -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; @end @implementation NodeWithHitTest -(instancetype)initWithColor:(UIColor *)color size:(CGSize)size { self = [super initWithColor:color size:size]; self.userInteractionEnabled = YES; return self; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"%@ hit", self.name); } @end @implementation MyScene -(id)initWithSize:(CGSize)size { if (self = [super […]