2016-05-26 48 views
1

在我的GameViewController.swift中我有一個名爲resumeGameScene的函數。在那個函數中,我啓動了3個定時器。所有這些都在我的GameScene.swift文件中調用3個獨立的函數(lane1,lane2和lane3)。我嘗試了製作我的函數類的功能,但這不起作用,因爲我在這些函數(lane1,lane2和lane3)中有更多的函數和變量。GameViewController中的NSTimer中的GameScene中定義的調用函數

GameViewController.swift:

func resumeGameScene() { 
    if (GameScene.unarchiveFromFile("GameScene") as? GameScene) != nil 
    { 
     let skView = self.view as! SKView 

     if skView.scene != nil 
     { 
      skView.paused = false 

      if resumeTime1 != nil && resumeTime2 != nil && resumeTime3 != nil 
      { 

       timer1 = NSTimer.scheduledTimerWithTimeInterval(resumeTime1!, target: self, selector: #selector(GameScene.lane1), userInfo: nil, repeats: false) 

       timer2 = NSTimer.scheduledTimerWithTimeInterval(resumeTime2!, target: self, selector: #selector(GameScene.lane2), userInfo: nil, repeats: false) 

       timer3 = NSTimer.scheduledTimerWithTimeInterval(resumeTime3!, target: self, selector: #selector(GameScene.lane3), userInfo: nil, repeats: false) 



      } 

     } 
    } 
} 

GameScene.swift:

func lane1() 
{ 


    let randomNum = arc4random_uniform(100) + 1 

    levels() 

    if randomNum < 46 
    { 
     mouseFire(1, laneFire: fire) 

    } 
    else 
    { 
     enemyFire(1, laneFire: fire) 

    } 

}//End of lane1 func 


func lane2() 
{ 

    let randomNum = arc4random_uniform(100) + 1 

    levels() 

    if randomNum < 46 
    { 
     mouseFire(3, laneFire: fire) 

    } 
    else 
    { 
     enemyFire(3, laneFire: fire) 

    } 

}//End of Lane2 func 


func lane3() 
{ 


    let randomNum = arc4random_uniform(100) + 1 

    levels() 

    if randomNum < 46 
    { 
     mouseFire(5, laneFire: fire) 

    } 
    else 
    { 
     enemyFire(5, laneFire: fire) 

    } 

}//End of Lane3 func 

回答

0

你的目標被self因此選擇器將在self它是GameViewController調用。由於您的選擇器不在GameViewController因此這不起作用。您需要創建GameScene的對象並將其傳遞給目標。

+0

謝謝!你如何創建GameScene的對象並將其傳遞給目標?對不起,我是一個新的編碼器 –

相關問題