sprite kit - sknode can't see added children -
here created menu class contains few items. want display these sprites in main class. experimented creating object associating sknode class in touches began method, when added menu object in main class using addchild thing, nothing showed up.
class menu:sknode { let background = skspritenode(imagenamed:"background") required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } override init(){ super.init() var fixedsize = self.frame.width/11 background.size = cgsizemake(self.frame.width-fixedsize, self.frame.size.height-fixedsize) background.position = cgpointmake(self.frame.size.width/2, self.frame.size.height/2) self.addchild(background) } } //in main method said let settings = menu() self.addchild(settings) nothing shows
the frame
property of sknode
equal cgrectzero
, when try set size of background node end cgrectzero
.
an easy fix problem add custom initializer , call size of scene.
class menu:sknode { let background = skspritenode(imagenamed:"background") required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } init(size: cgsize) { super.init() var fixedsize = size.width/11 background.size = cgsizemake(size.width-fixedsize, size.height-fixedsize) background.position = cgpointmake(size.width/2, size.height/2) self.addchild(background) } }
Comments
Post a Comment