
[英]How to hit objects with finger movement in 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.