Subclass SKSpriteNode

I'm trying to create my own SKSpriteNode by subclassing SKSpriteNode using swift here's the code:

import Foundation
import SpriteKit

class CustomNode:SKSpriteNode{

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init() {
    super.init()
    }
}

      

When I add it to the scene I got fatal error: using unimplemented initializer 'init (texture: color: size :)' for class 'Sandbox.CustomNode'

if i change

  super.init()

      

for

 super.init(texture: nil, color:UIColor.whiteColor(),size: CGRect(0,0,100,100))

      

I got a compiler error: "Additional argument" color "in the call.

I am using XCode 6 beta 7. Its an iOS project.

+3


source to share


1 answer


This error message is not entirely obvious, but it can be caused by incorrectly passing arguments to the method. In this case, the problem is that you are passing CGRect where the argument should be CGSize. This code should work for you.



super.init(texture: nil, color:UIColor.whiteColor(),size: CGSize(width: 100.0, height: 100.0))

      

+6


source







All Articles