2017-02-19 4 views
0

私は2つのシーン、FarmSceneとWoodSceneがあるゲームを持っています。 各シーンには.SKSファイルと.swiftファイルがあります。設計するものとコード化するものです。私の以前のゲームで別の.SKSファイルに移動する正しい方法

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    for touch in touches { 
     let location = touch.location(in: self) 
     let node : SKNode = self.atPoint(location) 
     if node.name == "WoodIcon" { 
      if let view = self.view as! SKView? { 
       // Load the SKScene from 'GameScene.sks' 
       if let scene = SKScene(fileNamed: "WoodScene") { 
        // Set the scale mode to scale to fit the window 
        scene.scaleMode = .aspectFill 

        // Present the scene 
        view.presentScene(scene) 
       } 
      } 
     } 
    } 
} 

私は別のシーンに移動するためにSKTransitionを使用しました、そしてそれを私はフリップのようないくつかのクールな遷移を行うことができ、フェード:私はこのようなWoodSceneにFarmSceneから移動することができた 押してください。

Xcodeでシーンデザイナを使用しているときに、これがシーンを変更する「正しい」方法であるかどうか疑問に思っていましたか?それとも、私は何かを逃しています。

お待ちしております。

答えて

0

私はループでそのようにはしませんが、プレゼンテーションコードを複数回実行することを避けるためです。あなたはこのような何かを行うことができ、コードでカスタム移行行いたい場合は多分ガード声明も

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    // Guard to just use the first touch 
    guard let touch = touches.first else { return } 
    let location = touch.location(in: self) 
    let node : SKNode = self.atPoint(location) 
    if node.name == "WoodIcon" { 
     if let view = self.view as! SKView? { 
      // Load the SKScene from 'GameScene.sks' 
      if let scene = SKScene(fileNamed: "WoodScene") { 
       // Set the scale mode to scale to fit the window 
       scene.scaleMode = .aspectFill 

       // Present the scene 
       view.presentScene(scene) 
      } 
     } 
    } 
} 

とセットアップあなたのtouchesBegan方法:

func customTransition() { 

    // Wait three seconds then present a custom scene transition 
    let wait = SKAction.wait(forDuration: 3.0) 
    let block = SKAction.run { 

     // Obviously use whatever scene you want, this is just a regular GameScene file with a size initializer 
     let newScene = SKScene(fileNamed: "fileName")! 
     newScene.scaleMode = .aspectFill 
     let transitionAction = SKTransition.flipHorizontal(withDuration: 0.5) 
     self.view?.presentScene(newScene, transition: transitionAction) 

    } 
    self.run(SKAction.sequence([wait, block])) 

} 

を私は右があると言わないだろうまたは間違った方法で、あなたが見た目に変わってほしいと思う方法についての好みだけです。

関連する問題