2016-03-08 34 views
1

我有五個iPad場景和5個iPhone場景在我的GVC中我有這個,我可以調用歡迎場景和Hud場景沒有問題,但我無法複製其他場景的相同呼叫。我不知道它是否是大括號,但我似乎無法將其他iPad的場景稱爲默認iPhone場景。 (相信我,當HUD出現時我非常興奮。)有人可以就我的代碼結構給出一些建議。請....多個sks文件,根據GVC在SpriteKit中調用適當的場景

import SpriteKit 
class GameViewController: UIViewController { 


    override func viewDidLoad() { 
     super.viewDidLoad() 

     if (UIDevice.currentDevice().userInterfaceIdiom == .Phone) { 

     if let scene = WelcomeScene(fileNamed:"WelcomeScene") { 

     let skView = self.view as! SKView 
     skView.showsFPS = GlobalData.Constant.DEV.DEBUG 
     skView.showsNodeCount = GlobalData.Constant.DEV.DEBUG 
     skView.ignoresSiblingOrder = true 
     scene.scaleMode = .AspectFill 
     skView.presentScene(scene) 


    } 

     } else { 

      if let scene = WelcomeScenePad(fileNamed: "WelcomeScenePad") { 
       let skView = self.view as! SKView 
       skView.showsFPS = GlobalData.Constant.DEV.DEBUG 
       skView.showsNodeCount = GlobalData.Constant.DEV.DEBUG 
       skView.ignoresSiblingOrder = true 
       scene.scaleMode = .AspectFill 
       skView.presentScene(scene) 

       if let scene = HudScenePad(fileNamed: "HudScenePad") { 
        let skView = self.view as! SKView 
        skView.showsNodeCount = GlobalData.Constant.DEV.DEBUG 
        skView.ignoresSiblingOrder = true 
        scene.scaleMode = .AspectFill 
        skView.presentScene(scene) 
       } 



      } else if let scene = WelcomeScene(fileNamed:"WelcomeScene") { 

       let skView = self.view as! SKView 
       skView.showsFPS = GlobalData.Constant.DEV.DEBUG 
       skView.showsNodeCount = GlobalData.Constant.DEV.DEBUG 
       skView.ignoresSiblingOrder = true 
       scene.scaleMode = .AspectFill 
       skView.presentScene(scene) 
      } 


     } 



    } 




    override func prefersStatusBarHidden() -> Bool { 
     return false 
    } 

    override func shouldAutorotate() -> Bool { 
     return true 
    } 

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 

     if UIDevice.currentDevice().userInterfaceIdiom == .Phone { 

      return .AllButUpsideDown 

     } else { 

      return .All 

    } 




} 


    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Release any cached data, images, etc that aren't in use. 
    } 

    } 

這段代碼讓我知道,遊戲場景是要正確SKS文件,並在編輯器打印的值,來驗證,這是我GAMEOVER功能。

if (UIDevice.currentDevice().userInterfaceIdiom == .Pad){ 

     if let _ = SceneTypePad(rawValue: fullSKSNameToLoad + String("Pad")) { 

      fullSKSNameToLoad = "fileNamed" + "Pad" 

      goToScenePad(SceneTypePad.DebateScene1Pad) 
      print(("Went to DebateScenePad")) 
      _ = SKTransition.fadeWithDuration(3) 

      _ = DebateScene1Pad() 


     } 
    } else if (UIDevice.currentDevice().userInterfaceIdiom == .Phone){ 
     goToScene(SceneType.DebateScene1) 
     (print("Went to DebateScenePhone")) 
     _ = SKTransition.fadeWithDuration(3) 

     _ = DebateScene1() 

    } 

三秒鐘的等待時間太長BTW ... :)

回答

0

我需要創建一個新的靜態變量調用SKS墊一幕我全球國際/基地場景文件。 Noob錯誤。當複製新文件的代碼時,要明智地寫字,當複製swift文件時,請仔細檢查變量。此外,讓頭腦休息是很好的,個人在編碼14小時後無法保持注意力,並保持敏銳。......散步,用清新的頭腦進行整理。在這項業務中,截止日期至關重要,但有時壓力會帶來愚蠢的決定,而這些決定很容易解決。

static var previousScenePad:SceneTypePad? 

static var nextScenePad:SceneTypePad? 
if (UIDevice.currentDevice().userInterfaceIdiom == .Phone) { 

if (UIDevice.currentDevice().userInterfaceIdiom == .Pad){ 

    if let _ = SceneTypePad(rawValue: fullSKSNameToLoad + String("Pad")) { 

     fullSKSNameToLoad = "fileNamed" + "Pad" 

    } 
} else if (UIDevice.currentDevice().userInterfaceIdiom == .Phone){ 


    } 

在調用特定的SKS文件時,在GVC中工作。很明顯,它基於使用基類中定義的正確的fileName「」呈現正確的視圖,是的,我知道有更好的方法來使用一個SKS文件,並使用相機節點來調整視圖。當談到內容,並有更多的空間時,它有機會創造更多像素和更多空間的不同體驗。資產同樣重要,因爲在開始時我每個設備都會調用錯誤的資產,所以我決定硬編碼,我的外觀尺寸因素不會丟失。最終的結果將是一個跨平臺的通用應用程序。如果你的優化是正確的,我可以凝聚一個140MB的應用程序,到76MB,即使我添加了5個新的場景到我的應用程序包。檢查你的背景音樂,檢查你的聲音效果和PNG文件。限制發射器的效果看起來不錯。您可以隨時返回並在下次更新中找到更乾淨的方法!