ios - found nil while unwrapping an Optional value - spriteKit -
I have a problem in my touch event function, it says "Fatal error: unexpectedly while opening an optional value Zero found "I'm trying to click on a node under a label,
overview to touchesBegan function. (Touches: NSSet !, withEvent Event: UIEvent) {Location: CGPoint = touches.anyObject (). LocationInNode (self) nodes: For NSArray = nodesAtPoint (space) node: {println ("node name:" + node.name) // here error in anyObject nodes // here error}
Error:
Fatal error: node name: mylabel node unexpectedly while unwrapping an optional value equal to
The console output found name: MyNode
The problem only appears on my device, it works perfectly on the simulator. Xcode 6.4, SDK 8.0, Target 7.0, Device 7.1.2
Edit:
In this view, my only phantom code is score.text = " 0 "score.name =" scoreLabel "score.fontName =" Chalkduster "scores SKLabelNode = SKLabelNode (): When I click on it got unwrapped error
.fontSize = 42 score.zPosition = 100 score.fontColor = UIColor.redColor () score.position = CGPointMake (CGRectGetWidth (self.frame) - 50, CGRectGetHeight (self.frame) - 40) self.addChild (score)
Try this device for you:
override func touchesBegan (Touches: NSSet !, withEvent Event: UIEvent) {Location:. CGPoint = touches.anyObject () locationInNode (self) Go Nodes: NSArray = nodesAtPoint (for location) node: AnyObject {go in strands = node. The string name as the println ("node name: \ (strName)")}
Comments
Post a Comment