簡體   English   中英

從UIViewController呈現SKScene-Swift

[英]Present SKScene from UIViewController - Swift

我想使用UIViewController作為菜單,使用SKScene作為GameScene進行游戲。

當玩家按下菜單上的“播放”按鈕時,我想在菜單和GameScene之間進行以下轉換:

let nextScene = GameViewController()
self.presentViewController(nextScene, animated: true, completion: nil)

但是我得到了這個錯誤:

Could not cast value of type 'UIView' (0x19ff623e0) to 'SKView' (0x19f813e70).

請問我該怎么做?

你里面的代碼GameViewController正試圖把self.view作為SKView但它實際上是一個UIView

您將需要在情節提要/ xib中將views類設置為SKView ,或者在視圖控制器的loadView方法中自行創建。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM