问题
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:
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
}
来源:https://stackoverflow.com/questions/23132020/sprite-kit-objective-c-what-is-the-touch-indicator-for-objects