2016-04-06 32 views
1

我試圖呈現一個菜單(GameViewController)。我嘗試在GameScene執行這一招:類型'GameScene'的值在Swift中沒有成員'presentViewController'

let secondViewController:GameViewController = GameViewController() 

self.presentViewController(secondViewController, animated: true, completion: nil) 

,但有一個在self.presentViewController(secondViewController, animated: true, completion: nil)行,它說「價值型‘GameScene’沒有成員‘presentViewController’斯威夫特」的錯誤。我無法使用.presentViewController執行移動,它需要以編程方式完成,並且不使用segues,而必須能夠在SKScene中使用。

由於提前, 尼爾

+0

你需要從'UIViewController'調用'presentViewController'。 'GameScene'不是視圖控制器。 – rmaddy

+0

@rmaddy是的,但我怎麼稱呼它呢? –

+0

@rmaddy我得到一個打印輸出嘗試在上呈現,它的視圖不在窗口層次結構中! 當我嘗試這個辦法:讓secondViewController:GameViewController = GameViewController() VAR viewh =的UIViewController() viewh.presentViewController(secondViewController,動畫:真,完成:無) –

回答

0

據蘋果公司稱,每一個不同的場景或畫面在遊戲應該用不同的SKScene對象呈現。

單個GameViewContoller和單個SKView可用於呈現許多不同的場景,如主菜單和遊戲中的關卡。

例如從SKScene類參考SKView使用self.view並告訴它顯示您的主菜單SKScene

相關問題