Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclassing SKSpriteNode

i'm trying to create a custom SKSpriteNode, by subclassing SKSpriteNode, using swift here 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: use of 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 the compiler error:"Extra Argument 'color' in call.

I'm using XCode 6, beta 7. Its a iOS project.

like image 638
MiguelSlv Avatar asked Mar 18 '23 12:03

MiguelSlv


1 Answers

That error message isn't exactly obvious, but it can be produced by incorrectly passing arguments to a method. In this case, the problem is that you're passing a CGRect, where the argument is supposed to be CGSize. This code should work for you.

super.init(texture: nil, color:UIColor.whiteColor(),size: CGSize(width: 100.0, height: 100.0))
like image 163
Mick MacCallum Avatar answered Mar 29 '23 17:03

Mick MacCallum