Ios SpriteKit-停止点击Sprite对儿童的影响
我目前使用以下命令使用SpriteKit创建带有文本的按钮:Ios SpriteKit-停止点击Sprite对儿童的影响,ios,sprite-kit,Ios,Sprite Kit,我目前使用以下命令使用SpriteKit创建带有文本的按钮: SKLabelNode *startButtonText = [SKLabelNode labelNodeWithFontNamed:@"Verdana-Bold"]; startButtonText.text = @"Start"; startButtonText.fontColor = [SKColor colorWithRed:1 green:1 blue:1 alpha:1]; startButtonText.fontSize
SKLabelNode *startButtonText = [SKLabelNode labelNodeWithFontNamed:@"Verdana-Bold"];
startButtonText.text = @"Start";
startButtonText.fontColor = [SKColor colorWithRed:1 green:1 blue:1 alpha:1];
startButtonText.fontSize = 24;
startButtonText.position = CGPointMake(self.size.width/2, self.size.height/2-10);
startButtonText.name=@"startButton";
SKShapeNode *startButton = [[SKShapeNode alloc] init];
startButton.path = [UIBezierPath bezierPathWithRect:CGRectMake(center.x-65.0 , center.y-20.0, 130.0, 40.0)].CGPath;
startButton.fillColor = [SKColor colorWithRed:0.188 green:0.196 blue:0.161 alpha:1];
startButton.strokeColor = nill;
startButtonText.name=@"startButton";
[startButton addChild:startButtonText];
[self addChild:startButton];
我的目标是使触摸屏时,触摸屏仅注册startButton,而不是通过以下方式注册startButtonText:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
NSLog(@"%@",node.name);
}
在动作脚本中,您只需使用:
mouseChildren = false;
这是否可行?为两个按钮指定不同的名称。您的代码中似乎存在复制粘贴错误。 然后检查触摸开始时按下了哪个按钮,并以相同的方式做出反应:
if ([node.name isEqualToString:@"startButton"]||[node.name isEqualToString:@"startButtonText"]) {
...
}
您已经将
startbuttonext
和startButton
的name属性设置为@“startButton”
。这可能就是为什么touch-delegate方法中会记录相同的名称。