2016-06-26 4 views
0

Ich wollte wissen, wie der Bildschirm blinken kann, wenn ich den Bildschirm berühre. Ich hatte versucht, colorizeWhitColor, aber es nur den Hintergrund eingefärbt, und ich weiß nicht, wie Sie zu der gleichen Farbe zurückkehren.Wie kann ich den gesamten Bildschirm anzeigen?

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

Klasse GameViewController: UIViewController {

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)) 



    } 



    } 

Antwort

2

In GameViewController.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 
    } 
} 

In GameScene.swift:

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

warum halten Sie es mich Talling: " Verwendung des unaufgelösten Identifikators: viewController " –

+0

@ DiegoBenítez Wo rufst du es an? Sie müssen auf dem 'UIViewController' mit den Funktionen sein, damit es funktioniert. – skunkmb

+0

Ich habe den Code auf meine Frage @skunkmb –