Sprite Kit Button touch location error | Swift -
i'm trying make button that's sklabelnode. when gets pressed, it's supposed change scenes, there wrong line location declared.
override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { super.touchesbegan(touches, withevent: event) let location = touches.locationinnode(self) let touchednode = self.nodeatpoint(location) if touchednode.name == "startgamebutton" { let transition = sktransition.revealwithdirection(sktransitiondirection.down, duration: 1.0) let scene = gamescene(size: self.scene.size) scene.scalemode = skscenescalemode.aspectfill self.scene.view.presentscene(scene, transition: transition) } } the error here on line.
let location = touches.locationinnode(self) it reads
'set< nsobject>' not have member named 'locationinnode'
i'm not sure how fix it. i've looked @ lot of working button templates, mine has error.
the problem error states - set<nsobject> doesn't have method named locationinnode. need retrieve object out of set; check it's uitouch object; if is, can use touch location. try:
override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { if let location = (touches.first as? uitouch)?.locationinnode(self) { // ... } } or
if let touch = touches.first as? uitouch { let location = touch.locationinnode(self) // ... }
Comments
Post a Comment