如何刷新整个屏幕?

时间:2016-06-26 20:06:57

标签: swift sprite-kit

我想知道当我触摸屏幕时屏幕是如何闪烁的。我试过colorizeWhitColor,但它只为背景着色,我不知道如何恢复相同的颜色。

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

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



    }



    }

1 个答案:

答案 0 :(得分:2)

在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
    }
}

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

        }
    }
}