繁体   English   中英

Sprite Kit / Objective C:什么是物体的“触摸指示器”

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

我指的是SpriteKit游戏的菜单屏幕。 我使用图像SpriteNodes作为开始和选项按钮。

如果我触摸开始按钮,我想更改为“游戏视图”,如果按下选项按钮,则要更改为“选项视图”。

应该是一个简单的问题,但是我找不到任何资源。

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    
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM