【发布时间】:2014-08-26 23:31:59
【问题描述】:
我尝试使用 spriteKit 制作一个应用程序,其中当用户触摸 sprite 节点时,会有一条 NSLog 消息表明该节点已被触摸。 我试图通过将触摸节点的名称与我检查是否被触摸的节点名称进行比较来做到这一点。问题是系统识别出节点被触摸了,尽管它没有被触摸。我认为是节点区域有问题,系统认为某个节点在某处,而绝对不是。
-(void)selectNodeForTouch:(CGPoint)touchLocation
{
if([[touchedNode name] isEqualToString:@"menuPlayButton"]){
NSLog(@"Pressed");
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
CGPoint positionInScene = [touch locationInNode:self];
[self selectNodeForTouch:positionInScene];
}
}
任何想法可能是什么问题? 在此先感谢
【问题讨论】:
-
该代码没有根据触摸位置选择节点,并且您没有包含分配touchNode的代码。
标签: ios sprite-kit skspritenode touch-event