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
Post a Comment