Swift: Background Color (SpriteKit)

I create a game, the background color is white, starting with this:

self.backgroundColor = SKColor.whiteColor()

So, when the game starts white, this is the background. I have a scoring system, so basically I want the colors to change when a certain result is achieved:

if score < 100{
            enemy.runAction(SKAction.moveTo(mainBall.position, duration:3))  
        }
        else if score >= 100 && score < 200{
            enemy.runAction(SKAction.moveTo(mainBall.position, duration:2.5))
            self.backgroundColor = SKColor.purpleColor()
        }
        else if score >= 200 && score < 300{
            enemy.runAction(SKAction.moveTo(mainBall.position, duration:2))
            self.backgroundColor = SKColor.greenColor()
        }

However, this method is very awkward and looks pretty awful if I'm honest. Everything in my game is fluid and contains attenuation when removed from the scene using:

livesLabel.runAction(SKAction.fadeInWithDuration(0.5))

But I'm not sure how I will do this with the background color. If I use the above example with backgroundColor like

self.backgroundColor = SKAction.fadeInWithDuration(SKColor.purpleColor())

I get the error "Can't call" fadeInWithDuration "with an argument list of type" (UIColor) "

. , . ,

+1
3

, colorizeWithColor SKAction. ...

runAction(SKAction.colorizeWithColor(SKColor.purpleColor(), colorBlendFactor: 1.0, duration: 2.0))
+3

viewDidLoad , ,

    self.view.backgroundColor = UIColor.blueColor()
    UIView.animateWithDuration(1.0, delay: 1.0, options: nil, animations: { () -> Void in
        self.view.backgroundColor = UIColor.greenColor()
    }, completion: nil)

, , -

    if (score < 100){
        enemy.runAction(SKAction.moveTo(mainBall.position, duration:3))  
    }
    else if (score >= 100 && score < 200){
        enemy.runAction(SKAction.moveTo(mainBall.position, duration:2.5))
        UIView.animateWithDuration(0.5, animations: { () -> Void in
           self.backgroundColor = SKColor.purpleColor()
       })
    }
    else if (score >= 200 && score < 300){
        enemy.runAction(SKAction.moveTo(mainBall.position, duration:2))
         UIView.animateWithDuration(0.5, animations: { () -> Void in
           self.backgroundColor = SKColor.greenColor()
    })
    }`
+2

if override func update(currentTime: NSTimeInterval) ( ).

, () if, , self backgroundColor.

0

All Articles