检测button的三angular形网格中的触摸?

在下面的照片中,每个三angular形都是一个单独的子类SKShapeNode。 你如何识别哪个三angular形被触动? 目前在现场的toucheBegan:方法中,触摸网格会检测两个三angular形,因为它们的框架是方形的。

在这里输入图像说明

我设法解决了这个问题,通过设置绘制三angular形作为Triangle类属性的UIBezierPathpath。 在场景的toucheBegan:方法中,我检查触摸是否包含在Triangle的touchableArea UIBezierPath属性中。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint position = [touch locationInNode:self]; NSArray *nodes = [self nodesAtPoint:position]; for (TrianglePiece *triangle in nodes) { if ([triangle isKindOfClass:[TrianglePiece class]]) { position = [touch locationInNode:triangle]; if ([triangle.touchableArea containsPoint:position]) { // Perform logic here. } } } }