簡體   English   中英

SKNode不在場景中顯示

[英]SKNodes don't show in scene

我設置了場景,並且一切正常。 它看起來像這樣: 在此處輸入圖片說明

但是控制器是在Main.storyboard中設置的,我想擺脫它。 所以我做了這樣的事情:

    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    window?.rootViewController = GameViewController()

在appDelegate和這:

override func loadView() {
    super.loadView()
    self.view = SKView()
}

在GameViewController中加載它。 第一次加載場景,但是只有綠色背景,沒有其他節點。 (節點計數器顯示正確的節點數。)

因此,我嘗試將ignoreSiblingOrder設置為true和false,包括scene.scaleMode的所有選項,而我獲得的最佳結果是使用scene.scaleMode = .resizeFill。 看起來像這樣: 在此處輸入圖片說明

編輯:圈子的位置:

greenOne.position = CGPoint(x: greenOne.radius + sticksOffset, y: greenOne.radius + sticksOffset)
redOne.position = CGPoint(x: self.frame.maxX - redOne.radius - sticksOffset / 2, y: view.bounds.size.height / 2)

試過這個,redOne出現在綠色旁邊

redOne.position = CGPoint(x: redOne.radius + 100, y: 200)

該視圖似乎不適合屏幕,並且太大了。

通過在GameViewController中更改視圖初始化來解決:

override func loadView() {
    super.loadView()

    self.view = SKView(frame: UIScreen.main.applicationFrame)
}

舊版本的視圖的寬度和高度為零,因此GameScene沒有任何尺寸。

暫無
暫無

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

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