Coder1000 Coder1000 - 1 year ago 133
Swift Question

How to gradually (animated) change background color in Spritekit?


Gradually change background color in Swift

Swift : Background Color fading animation (SpriteKit)

WHAT I CURRENTLY HAVE (not working):

class GameScene: SKScene, SKPhysicsContactDelegate{

var background = SKSpriteNode()

var colorizeToRed = SKAction()

override func didMoveToView(view: SKView) {

background = SKSpriteNode(color: UIColor.blueColor(), size: self.frame.size)

background.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)

background.zPosition = 15

colorizeToRed = SKAction.colorizeWithColor(SKColor(red: 90, green: 0, blue: 0, alpha: 1), colorBlendFactor: 1.0, duration: 2.0)





I don't see the background change color. The only time I see it change color is if I set it directly with no animation using
self.backgroundColor = UIColor().aColor

EDIT: In fact, I dont'even see the blue background... Something is wrong with my SKSpriteNode, but what ?


How to gradually (animated) change background color in Spritekit ?


1) YES, I have already tried changing the zPosition in case the SKNode was hidden.

2) YES, I have checked the doc for

3) YES, I am almost certain the solution to my problem is very simple (probably some mistake on my part), but what ?

4) YES, I am open to any suggestions telling me the error is somewhere else in my code, but only if you precise where that error might be.

5) NO, I will not post my ENTIRE code here, please ask for specific parts if necessary.

Thank you in advance for any help you provide ^^ !

Nik Nik
Answer Source

By the looks of it, I think you just forgot to add the background to the scene. Try this:


If that doesn't help, read on...

If you're just fading in an SKSpriteNode then you can use he SKAction.fadeIn to fade the node in. Just set its alpha to 0 to start and fade it in by doing something like this:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download