2014-03-06 67 views
1

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

我意识到我可能无法将其添加为场景的子视图,那么替代方案是什么,以便我可以在场景的顶部有一个可点按的按钮?

+2

请参考这里的答案:http://stackoverflow.com/questions/19082202/spritekit-setting-up-buttons-in-skscene – ZeMoon

+1

UIKit的视图(只能)添加到SKView,不现场或其他节点 – LearnCocos2D

回答

1

你可以选择下列方式之一:

1 - 类别SKSpriteNode作为一个按钮

2 - 在场景内实现触摸代表和回应,如果你的“按钮”节点被触摸

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

3 - 使用像SpriteKit Button这样的组件,可以找到here

+0

我认为#2是最好的解决方案。谢谢! –

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];