创建 SKShapeNode 的子类
Creating a subclass of 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
}
}
无法正确获取初始化程序。
我该怎么办?
尝试像这样更改您的初始化程序:
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
}
}
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
}
}
无法正确获取初始化程序。 我该怎么办?
尝试像这样更改您的初始化程序:
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
}
}