i'm trying build game (swift sprite kit) in background of scene change after user has passed number of scores. not working (in gamescene)
func addswitchbackgrounds() { let pointslable = mlpointslabel(num: 0) if (pointslable == 30) { let backgroundtexture = sktexture (imagenamed: "store") let backgroundimage = skspritenode (texture: backgroundtexture,size:view!.frame.size) backgroundimage.position = view!.center } } can help?
this simple example should point right way (just copy&paste see how works)...
import spritekit class gamescene: skscene, skphysicscontactdelegate { let backgroundnode = skspritenode(imagenamed: "background") var score = 0 let label = sklabelnode(fontnamed: "arialmt") override func didmovetoview(view: skview) { //setup scene backgroundnode.position = cgpoint(x: cgrectgetmidx(self.frame), y: cgrectgetmidy(self.frame)) label.position = cgpoint(x: cgrectgetmidx(self.frame), y: cgrectgetmidy(self.frame)) label.text = "score : 0" self.addchild(backgroundnode) self.addchild(label) } override func touchesbegan(touches: nsset, withevent event: uievent) { score++ if(score == 5){ self.backgroundnode.texture = sktexture(imagenamed: "background_v2") } label.text = "score : \(score)" } } first, make backgroundnode property , then, later on in code change texture. don't have make constant checks in update method current score. can make check when score increased. not sure call addswitchbackgrounds though, want know, there no need use update: method this.
Comments
Post a Comment