2017-08-18 9 views
-1

ボタンを押したときにシーンを切り替えようとしていますが、クリックすると何も起こりません。何も表示されません。エラーはありません、なぜ私はそれが動作していないのだろうかと思っています。 私がプログラムしたノードは正しいサイズと場所で表示されますが、タップすると何も通過しません。何か助けてくれてありがとう。シーンをボタンノードで切り替えるとエラーが発生する

コード:

class LevelScene: SKScene, SKPhysicsContactDelegate { 

    var isFingerOnBlock = false 
let LevelOneName = "levelOne" 

    override func didMove(to view: SKView) { 
     super.didMove(to: view) 
     let Pineapple = SKSpriteNode(imageNamed: "ball") 
     Pineapple.isUserInteractionEnabled = true 
     Pineapple.position = CGPoint(x: self.frame.midX - 200, y: self.frame.midY); 
     Pineapple.name = "pineapple" 
     addChild(Pineapple) 

    } 





    func touchesBegan(touches: NSSet, withEvent event: UIEvent) 
    { 
       let touch = touches.anyObject() as! UITouch 
     let location = touch.location(in: self) 
     let nodes = self.nodes(at: location) 

     for node in nodes 
     { 
      if node.name == "pineapple" 
      { 
      print("ceeds") 

       if let scene = GameScene(fileNamed:"GameScene") { 
        // Configure the view. 
        let skView = self.view! 
        skView.showsFPS = true 
        skView.showsNodeCount = true 

        /* Sprite Kit applies additional optimizations to improve rendering performance */ 
        skView.ignoresSiblingOrder = true 

        /* Set the scale mode to scale to fit the window */ 
        scene.scaleMode = .aspectFit 

        skView.presentScene(scene) 


       } 
       break 
      } 
     } 
} 

} 

答えて

0

あなたは

func touchesBegan(touches: NSSet, withEvent event: UIEvent) 

あり、内蔵機能その署名を何がなく、あなたがその関数を呼び出すことがないと宣言しています。したがって、あなたの機能はで、決してと呼ばれています。

+1

あなたはこの機能を実装しようと思っていますか? https://developer.apple.com/documentation/uikit/uiresponder/1621142-touchesbegan – matt

0

ありがとうMatt!私は自分のコードを修正しました:今動作します..

override func touchesBegan(_ touches: Set<UITouch>, 
         with event: UIEvent?) { 
     let touch = touches.first! 
     let location = touch.location(in: self) 
     let node : SKNode = self.atPoint(location) 
     if(atPoint(location) == node){ 
      if node.name == "levelOne" { 
       if let scene = GameScene(fileNamed:"GameScene") { 
        // Configure the view. 
        let skView = self.view as! SKView 
        skView.showsFPS = true 
        skView.showsNodeCount = true 

        /* Sprite Kit applies additional optimizations to improve rendering performance */ 
        skView.ignoresSiblingOrder = true 

        /* Set the scale mode to scale to fit the window */ 
        scene.scaleMode = .aspectFit 

        skView.presentScene(scene) 


       } 
      } 

     } 

} 
関連する問題