首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SpriteKit -停止点击雪碧对儿童的行动

SpriteKit -停止点击雪碧对儿童的行动
EN

Stack Overflow用户
提问于 2014-06-01 20:28:10
回答 1查看 57关注 0票数 0

目前,我使用以下方法创建一个使用SpriteKit的文本按钮:

代码语言:javascript
复制
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:

代码语言:javascript
复制
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    SKNode *node = [self nodeAtPoint:location];
    NSLog(@"%@",node.name);
}

在操作脚本中,只需使用:

代码语言:javascript
复制
mouseChildren = false;

这有可能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-01 21:12:40

给两个按钮取一个不同的名字。看起来您的代码中有一个复制和粘贴错误。然后签入您的touchesBegan,按下哪个按钮并以相同的方式作出反应:

代码语言:javascript
复制
if ([node.name isEqualToString:@"startButton"]||[node.name isEqualToString:@"startButtonText"]) {
...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23984167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档