将UIButton添加到SKScene

时间:2014-03-06 07:49:20

标签: ios objective-c uikit sprite-kit skscene

UIButton添加到SKScene的最佳方式是什么?

我意识到我可能无法将其添加为场景的子视图,那么还有什么可以让我在场景顶部有一个可点击的按钮?

2 个答案:

答案 0 :(得分:1)

您可以选择以下方式之一:

1 - 子类SKSpriteNode充当按钮

2 - 在场景中实现触摸代表,并在触摸“按钮”节点时做出响应

这个link将告诉你如何实现上述两个。

3 - 使用SpriteKit按钮之类的组件here

答案 1 :(得分:1)

 /// create a uibutton in skscene (spritkit)

      UIButton * startButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 60, 20)];
                startButton.backgroundColor = [UIColor redColor];

                [self.view addSubview:startButton];

/// if u want to connect it to a method or function /// 

[startButton addTarget:self action:@selector(StartBtn) forControlEvents:UIControlEventTouchUpInside];
相关问题