创建SKShapeNode的子类

时间:2015-08-11 07:18:07

标签: swift xcode7 skshapenode

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
    }

}

无法正确启动初始化程序。 我该怎么办?

1 个答案:

答案 0 :(得分:2)

尝试像这样更改初始化程序:

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
    }

}