Creating a subclass of SKShapeNode

2019-02-19 23:32发布

class ColorRectangle: SKShapeNode {

    var width: CGFloat!
    var height: CGFloat!
    var rectColor: UIColor!

    convenience init(rectOfSize: CGSize, colorOfRectangle rectColor: UIColor) {

        super.init(rectOfSize: rectOfSize)

        self.width = rectOfSize.width
        self.height = rectOfSize.height
        self.rectColor = rectColor

        self.fillColor = rectColor
        self.strokeColor = rectColor
    }

}

Can't get the initializer right. What do I do?

1条回答
We Are One
2楼-- · 2019-02-19 23:59

Try changing your initializer like this:

class ColorRectangle: SKShapeNode {

    var width: CGFloat!
    var height: CGFloat!
    var rectColor: UIColor!

    convenience init(rectOfSize: CGSize, colorOfRectangle rectColor: UIColor) {

        self.init()

        self.init(rectOfSize: rectOfSize)

        self.rectColor = rectColor

        self.fillColor = rectColor
        self.strokeColor = rectColor
    }

}
查看更多
登录 后发表回答