import SpriteKit
let BallCategoryName = "ball"
let PaddleCategoryName = "paddle"
let BlockCategoryName = "block"
let BlockNodeCategoryName = "blockNode"
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
super.didMoveToView(view)
// 1. Create a physics body that borders the screen
let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
// 2. Set the friction of that physicsBody to 0
borderBody.friction = 0
// 3. Set physicsBody of scene to borderBody
self.physicsBody = borderBody
physicsWorld.gravity = CGVectorMake(0, 0)
let ball = childNodeWithName(BallCategoryName) as! SKSpriteNode
ball.physicsBody!.applyImpulse(CGVectorMake(10, -10))
}
}
在这行代码中:
let ball = childNodeWithName(BallCategoryName) as SKSpriteNode
我收到此错误:
“主题1:EXC_BAD_INSTRUCTION(代码= EXC_1386_INVOP,子代码= 0x0)
为什么?
运行Xcode 版本6.4(6E35b)
答案 0 :(得分:0)
尝试使用初始球:
let ball : SKSpriteNode = childNodeWithName(BallCategoryName) as SKSpriteNode
如果您发现任何问题,请告诉我。
由于