Sprite Kit / Objective C : What is the “touch indicator” for objects

一个人想着一个人 提交于 2019-12-11 19:52:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!