2016-06-26 7 views
0

私は画面に触れると画面がどのように点滅するのか知りたかったのです。私はcolorizeWhitColorにしようとしましたが、それはバックグラウンドを色付けしただけで、同じ色に戻る方法はわかりません。画面全体をどのようにフラッシュできますか?

scene?.runAction(SKAction.colorizeWithColor(UIColor.blackColor(), colorBlendFactor: 1.0, duration: 0.5)) 

クラスGameViewController:のUIViewController GameViewController.swiftで{

let viewFlash = UIView.init(frame: UIScreen.mainScreen().bounds) 

override func viewDidLoad() { 
    super.viewDidLoad() 

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

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

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

     skView.presentScene(scene) 

      viewFlash.hidden = true 
      self.view.addSubview(viewFlash) 
     } 
     func flashScreen(color: UIColor, flashTime: NSTimeInterval){ 
      viewFlash.backgroundColor = color 
      viewFlash.hidden = false 



    NSTimer.scheduledTimerWithTimeInterval(flashTime, target: self, selector:#selector(ViewController.stopFlash), userInfo: nil, repeats: false) //here it tells me that 

    } 
     func stopFlash(){ 
      viewFlash.hidden = true 
     } 

    } 



override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 

    /* Called when a touch begins */ 




    if gameStarted == false { 

     flashScreen(UIColor.whiteColor(), 0.1) 


     circuloVerde.removeFromParent() 
     circuloMorado.removeFromParent() 
     circuloRojo.removeFromParent() 
     circuloBlanco.removeFromParent() 


     enemigoTimer = NSTimer.scheduledTimerWithTimeInterval(0.685, target: self, selector: Selector("enemigos"), userInfo: nil, repeats: true) 


     gameStarted = true 

     circuloPrincipal.runAction(SKAction.scaleTo(0.44, duration: 0.5)) 

    score = 0 

     scoreLabel.text = "\(score)" 

     hits = 0 

     highscoreLabel.runAction(SKAction.fadeOutWithDuration(0.5)) 



    } 



    } 

答えて

2

:GameScene.swiftで

import UIKit 
import SpriteKit 

class GameViewController: UIViewController { 

    let viewFlash = UIView.init(frame: UIScreen.mainScreen().bounds) 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     viewFlash.hidden = true 
     self.view.addSubview(viewFlash) 

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

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

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

      skView.presentScene(scene) 
     } 
    } 
    func flashScreen(color: UIColor, flashTime: NSTimeInterval){ 
     viewFlash.backgroundColor = color 
     viewFlash.hidden = false 
     NSTimer.scheduledTimerWithTimeInterval(flashTime, target: self, selector:#selector(self.stopFlash), userInfo: nil, repeats: false) 
    } 
    func stopFlash(){ 
     viewFlash.hidden = true 
    } 
} 

import SpriteKit 

class GameScene: SKScene { 

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 

     /* Called when a touch begins */ 

     if gameStarted == false { 

      //This is the new part 
      var parentVC = view?.window?.rootViewController as! GameViewController 
      parentVC.flashScreen(UIColor.whiteColor(), flashTime: 0.1) 
      //This is the new part 

      circuloVerde.removeFromParent() 
      circuloMorado.removeFromParent() 
      circuloRojo.removeFromParent() 
      circuloBlanco.removeFromParent() 


      enemigoTimer = NSTimer.scheduledTimerWithTimeInterval(0.685, target: self, selector: Selector("enemigos"), userInfo: nil, repeats: true) 


      gameStarted = true 

      circuloPrincipal.runAction(SKAction.scaleTo(0.44, duration: 0.5)) 

      score = 0 

      scoreLabel.text = "\(score)" 

      hits = 0 

      highscoreLabel.runAction(SKAction.fadeOutWithDuration(0.5)) 

     } 
    } 
} 
+0

なぜそれが私をtalling保つん。 "未解決の識別子の使用:viewController " –

+0

@DiegoBenítezどこに呼びますか?関数を使うためには、 'UIViewController'の上にいなければなりません。 – skunkmb

+0

私の質問にコードを追加しました@skunkmb –

関連する問題