在以下代码中,我不断收到“致命错误:在展开可选值时意外发现 nil”
let ballCategoryName = "ball"
class GameScene: SKScene, SKPhysicsContactDelegate {
override func didMoveToView(view: SKView) {
let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
borderBody.friction = 0
self.physicsBody = borderBody
let ball = childNodeWithName(ballCategoryName) as! SKSpriteNode
ball.position = CGPointMake(self.size.width / 2, self.size.height / 2)
ball.physicsBody?.dynamic = true
ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.size.height / 2)
ball.physicsBody!.applyImpulse(CGVector(dx: 2.0, dy: -2.0))
self.addChild(ball)
错误出现在“let ball = childNodeWithName(ballCategoryName) as!SKSpriteNode”想知道是否有人可以在这里帮助我了解为什么会出现这种情况