Sprite Kit / Objective C:什么是对象的“触摸指示器”
我指的是我的SpriteKit
游戏的菜单屏幕。 我使用图像SpriteNodes
作为开始和选项button。
如果我触摸开始button,我想要改变到“游戏视图”;如果按下了选项button,我想改变为“选项视图”。
应该是一个简单的问题,但我找不到任何资源。
在SpriteKit
用于检测哪个SKSpriteNode
被触摸,这里有属性.name
SKSpriteNode *toGame = [SKSpriteNode spriteNodeWithImageNamed:@"game"]; toGame.name = @"toGame"; ... SKSpriteNode *toOptions = [SKSpriteNode spriteNodeWithImageNamed:@"options"]; toOptions.name = @"toOptions"; ...
在touchesBegan
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInNode:self]; SKNode *node = [self nodeAtPoint:location]; if ([node.name isEqualToString:@"toGame"]) { //go to game scene } if ([node.name isEqualToString:@"toOptions"]) { // go to options scene }