Sprite Kit/Objective C:什么是“触摸指示器"?对于对象 [英] Sprite Kit / Objective C : What is the "touch indicator" for objects

查看:37
本文介绍了Sprite Kit/Objective C:什么是“触摸指示器"?对于对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

SpriteKit 中用于检测哪个 SKSpriteNode 被触摸有属性 .name>

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";
 ...

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    
 }

这篇关于Sprite Kit/Objective C:什么是“触摸指示器"?对于对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆