目前,我使用以下方法创建一个使用SpriteKit的文本按钮:
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;这有可能吗?
发布于 2014-06-01 21:12:40
给两个按钮取一个不同的名字。看起来您的代码中有一个复制和粘贴错误。然后签入您的touchesBegan,按下哪个按钮并以相同的方式作出反应:
if ([node.name isEqualToString:@"startButton"]||[node.name isEqualToString:@"startButtonText"]) {
...
}https://stackoverflow.com/questions/23984167
复制相似问题