Sprite Kit / Objective C : What is the “touch indi

2019-09-19 07:06发布

I am referring to the menu screen of my SpriteKit game. I used image SpriteNodes for the start and options button.

I want to change to the "game view" if I touch the start button, and "options view" if the options button's pressed.

Should be an easy question, but I couldn't find any resources for this.

1条回答
一夜七次
2楼-- · 2019-09-19 07:30

in SpriteKit for detect which SKSpriteNode is touched there is property .name

 SKSpriteNode *toGame = [SKSpriteNode spriteNodeWithImageNamed:@"game"];
 toGame.name = @"toGame";
 ...

 SKSpriteNode *toOptions = [SKSpriteNode spriteNodeWithImageNamed:@"options"];
 toOptions.name = @"toOptions";
 ...

after in 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    
 }
查看更多
登录 后发表回答