2
votes

I'm trying to subclass SKSpriteNode and during runtime I get a bad access error and I'm not sure why. Here is my code:

class Paddle: SKSpriteNode {

    override init(texture: SKTexture!, color: UIColor!, size: CGSize){
        super.init(texture: texture, color: color, size: size)
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}

Then in the parent class SKScene,

var paddle = Paddle(texture: SKTexture(), color: UIColor.blackColor(), size: CGSizeZero)
1
what line does the error point to?LearnCocos2D

1 Answers

1
votes

You can not pass the Paddle class a bunch of types, you have to pass it real information that conforms to those types. Also your syntax is incorrect.

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

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

Assign this Paddle class (which will be initialized when you assign it) to var paddle.

var paddle = Paddle()
self.addChild(paddle)