gpt4 book ai didi

iOS swift : EXC_BAD_INSTRUCTION

转载 作者:行者123 更新时间:2023-11-30 14:12:09 24 4
gpt4 key购买 nike

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))

}
}

在这行代码上:

让 ball = childNodeWithName(BallCategoryName) 作为 SKSpriteNode

我收到此错误:

"Thread 1:EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0)

为什么?

运行 Xcode版本6.4(6E35b)

最佳答案

尝试这个初始化球:

let ball : SKSpriteNode = childNodeWithName(BallCategoryName) as SKSpriteNode

如果您发现任何问题,请告诉我。

谢谢

关于iOS swift : EXC_BAD_INSTRUCTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31655168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com