2017-02-09 78 views

回答

0

一般情況下,你需要創建一個子節點首先

override init(size: CGSize){ 

    let playButton = SKLabelNode() 
    playButton.fontSize = 40 
    playButton.text = NA_MENU_BTN_PLAY 
    playButton.position = CGPoint(x: self.frame.midX, y: 300) 
    //give it an unique name 
    playButton.name = "Play" 
    playButton.zPosition = 3 
    addChild(playButton) 

} 

然後使用func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)處理觸摸事件

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    for touch in (touches){ 
     let location = touch.location(in: self) 
     let touchNode = atPoint(location) 

     if !((touchNode.name) != nil) { return } 

     switch touchNode.name! { 
      case "Play" : 
       //your logic here!! 
       let trialScene = TrialScene(size: self.size) 
       self.view! .presentScene(trialScene, transition: transition) 
     } 
    } 

} 
相關問題