Make SKSpriteNode subclass using Swift

不想你离开。 提交于 2019-12-03 09:44:47
Mike S

You have to call the designated initializer for SKSpriteNode. I'm actually surprised you didn't get another error about not full implementing SKSpriteNode, are you using an older Xcode6 beta maybe?

Since you have to use the designated initializer, you need to call super.init(texture: '', color: '', size: '').

It would be something like this:

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

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

Note: I also added the init for NSCoder which Xcode will require.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!