Swift 2 migration error: can no longer go to zero in the designated SKSpriteNode initializer

Trying to migrate my project to Swift 2.

I get a lot of compiler errors, most of which are easy to fix, as they are just syntactic changes.

However, I do not know how best to deal with this error:

When calling the designated initializer from my subclass SKSpriteNode, an error message appears: "Type" UIColor "does not comply with the protocol" NilLiteralConvertible "for transmission nilto color:

import SpriteKit

class MyClass: SKSpriteNode {

  init() {
    let texture = SKTexture(imageNamed: "MyTexture.png")
    super.init(texture: texture, color: nil, size: texture.size())
  }
}

I can get around this by passing UIColor.clearColor(), but I think this is not the right way to handle this.

Any suggestions that were highly appreciated, as well as what has changed here (of course, there was enough explanation link)?

+4
2

Swift 1.2 , , - , nil

Swift 2, , UIColor, (. docs)

UIColor.clearColor() !

+6

, ( , ), , , nil.

, :

convenience init(texture: SKTexture?, size: CGSize)

, , , UIColor UIColor.clearColor(). , , (1.0,1.0,1.0), :

convenience init(texture texture: SKTexture?)
//The size property of the sprite is set to the dimensions of the texture. The color property is set to white (1.0,1.0,1.0).

, ( , , ), - , RGB UIColor.

0

All Articles