基本上现在我获得了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];
}
我的问题是如何将这种方法更改为按钮?
最佳答案
也许给你的精灵一个“按钮”的名字,这样你就知道你触摸哪个
-(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
}
}
}
关于ios - 如何在Sprite套件中制作用于触摸的按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35214016/