sprite kit - SKLabelNode is not appearing on SKSpriteNode swift -


i'm trying add sklabelnode child of skspritenode:

var mainnode = skspritenode()  override func didmovetoview(view: skview) {      mainnode = skspritenode(color: uicolor.redcolor(), size: self.size)     mainnode.position = cgpoint(x: cgrectgetmidx(self.frame), y: cgrectgetmidy(self.frame))     mainnode.zposition = -2     mainnode.name = "mainnode"     self.addchild(mainnode)      let mylabel = sklabelnode(fontnamed:"chalkduster")     mylabel.text = "hello, world!"     mylabel.fontsize = 45     mylabel.position = cgpoint(x:cgrectgetmidx(mainnode.frame), y:cgrectgetmidy(mainnode.frame))      mainnode.addchild(mylabel) } 

but sklabelnode not appearing. tried change zposition, doesn't work anyway.

if add label on scene (self.addchild(mylabel)) works fine

your problem cgpoint(x:cgrectgetmidx(mainnode.frame), y:cgrectgetmidy(mainnode.frame)) put label out of bounds. if want sklabelnode horizontally , vertically centered, can

let mylabel = sklabelnode(fontnamed:"chalkduster") mylabel.text = "hello, world!" mylabel.fontsize = 45 mylabel.horizontalalignmentmode = .center mylabel.verticalalignmentmode = .center mainnode.addchild(mylabel) 

Comments