如何在 Sprite 工具包中为 touchesBegan 制作一个按钮
how to make a button in Sprite kit for touchesBegan
基本上现在我得到了 TitleScene,我的游戏的当前名称在哪里,当点击屏幕上的任何地方时它会跳转到 GameScene,它看起来像这样:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
SKScene *scene = [GameScene sceneWithSize:self.size];
SKTransition *transition = [SKTransition pushWithDirection:SKTransitionDirectionUp duration:1.0f];
[self.view presentScene:scene transition:transition];
}
我的问题是如何将此方法更改为按钮?
也许可以给你的精灵起一个名字 "button" 这样你就知道你在触摸哪一个
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
SKNode *touchedNode = [self nodeAtPoint:location];
if (touchedNode && [touchedNode.name isEqual:@"button"]) {
// your code here
}
}
}
基本上现在我得到了 TitleScene,我的游戏的当前名称在哪里,当点击屏幕上的任何地方时它会跳转到 GameScene,它看起来像这样:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
SKScene *scene = [GameScene sceneWithSize:self.size];
SKTransition *transition = [SKTransition pushWithDirection:SKTransitionDirectionUp duration:1.0f];
[self.view presentScene:scene transition:transition];
}
我的问题是如何将此方法更改为按钮?
也许可以给你的精灵起一个名字 "button" 这样你就知道你在触摸哪一个
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
SKNode *touchedNode = [self nodeAtPoint:location];
if (touchedNode && [touchedNode.name isEqual:@"button"]) {
// your code here
}
}
}