xcode - Using custom SKNodes in spritekit scene editor -
i want create level using custom subclasses of sknode. tried adding sknode scene editor , using "custom class" tab give class want did absolutely nothing. node still empty , nothing show when run simulator. also, make sure class works, added instance of scene programmatically see if shows , does.
how add custom nodes scene through scene editor?
here's custom class code:
class player: skspritenode { required init?(coder adecoder: nscoder) { super.init(coder: adecoder) print("test") self.addchild(skspritenode(imagenamed: "player.png")) } }
there 2 things need do:
1) when setting custom class have prefix class name app's name; my_app_name.myclass
example, _
represents space.
2) sknode
subclass needs implement required init?(coder adecoder: nscoder)
.
for example, in project called 'mygame':
class mynode: skspritenode { // set after node has been initaliser init(coder:) var somestat: int = 0 required init?(coder adecoder: nscoder) { super.init(coder: adecoder) // check worked: print("yup, working") } }
Comments
Post a Comment