2014-03-06 65 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];