Pergunta

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.

Foi útil?

Solução

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    
 }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top