2016-11-09 57 views
1

我有SKLabelNode的子類,真實實例化三分四次,每一個名字和一個目標:分類爲SKLabelNode以呈現場景,如何?

// 

import SpriteKit 

class MenuButton: SKLabelNode { 

    var goesTo = SKScene() 

    override init() { 
     super.init() 
     print("test... did this get called? WTF? HOW/WHY/WHERE?") 
    } 

    convenience init(text: String, color: SKColor, destination: SKScene){ 
     self.init() 
     self.text = text 
     self.color = color 

     goesTo = destination 
    } 

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
     let nextScene = goesTo 
     // .....????????????????? 
     // HOW DO I GET THIS TO FIND ITS SCENE... 
     // THEN ITS VIEW, THEN PRESENT this nextScene???? 

    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError("init(coder:) has not been implemented") 
    } 

} 

我在茫然,如何在視圖得到我需要調用現場改變。

回答

2

每個SKNode都有一個scene屬性,它返回節點所在的場景。

而且每SKScene作爲view屬性,因此

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    let nextScene = goesTo 

    self.scene?.view?.presentScene(nextScene) 

} 
+0

謝謝你!比我對這個問題的方法好得多;)'let myPointlessView = SKView()myPointlessView.presentScene(nextScene)' – Confused

相關問題