ios - Can't reference Xcode GameScene.sks with swift -


i beginer , starting first swift game. seems gamescene.sks interface extrememly easy position labels , nodes each level, having trouble figuring out how reference nodes swift. example dragged on label act timer, dont know how update label text code. thinking like:

func timerdidfire(){     countdown--     sklabelnode.name("countdowntimerlabel").text = countdown } 

you need use childnodewithname method on sknode. example:

func timerdidfire() {     let label = childnodewithname("countdowntimerlabel") as! sklabelnode     label.text = --countdown      // believe appropriate case force unwrapping since you're going      // want know if scene doesn't contain label node.  } 

since you're going accessing sklabelnode often, , takes time search through node tree (not bear in mind), may idea keep reference label. example, in skscene subclass:

lazy var labelnode: sklabelnode = self.childnodewithname("countdowntimerlabel") as! sklabelnode 

on related note, if you're looking multiple nodes there's enumeratechildnodeswithname(_:usingblock:), on sknode.

finally, more information have @ apple's wwdc 2014 talk: best practices building spritekit games cover both methods mentioned.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -