子类化 SKSpriteNode
你可以子类 SKSpriteNode
并定义你自己的精灵类型。
class Hero: SKSpriteNode {
//Use a convenience init when you want to hard code values
convenience init() {
let texture = SKTexture(imageNamed: "Hero")
self.init(texture: texture, color: .clearColor(), size: texture.size())
}
//We need to override this to allow for class to work in SpriteKit Scene Builder
required init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
}
//Override this to allow Hero to have access all convenience init methods
override init(texture: SKTexture?, color: UIColor, size: CGSize)
{
super.init(texture: texture, color: color, size: size)
}
}