错误访问物理场导致应用程序崩溃 SWIFT、XCODE
bad access physics field crashes application SWIFT, XCODE
嘿,我有一个 world/Scene,里面有一个人,所以我决定制作一个物理场来充当重力。所以我可以使用 swift 毫无问题地对其进行编码,但是后来我 运行 该应用程序并且它一直给我错误的访问权限。没有这些代码行,我的 app/scenekit 游戏可以顺利运行任何帮助。请查看所附图片谢谢
代码:
// I declared field owner up at the top here
class GameViewController: UIViewController, ADBannerViewDelegate, SKPhysicsContactDelegate, SKSceneDelegate, SCNSceneRendererDelegate, SCNPhysicsContactDelegate{
var fieldOwner = SCNNode()
override func viewDidLoad() {
super.viewDidLoad()
//Force field to act as Gravity
fieldOwner = SCNNode()
fieldOwner.position = SCNVector3(x: 0, y: -5, z: -5)
let field: SCNPhysicsField = SCNPhysicsField.radialGravityField()
field.halfExtent = SCNVector3Make(100, 100, 100)
field.minimumDistance = 20.0
field.falloffExponent = 0
self.fieldOwner.physicsField!.strength = 0.0
self.fieldOwner.physicsField = field
scnView.scene!.rootNode.addChildNode(fieldOwner)
}
}
看起来您在设置之前正在访问 self.fieldOwner.physicsField
。尝试在本地 field
变量上设置强度:
改变
self.fieldOwner.physicsField!.strength = 0.0
到
field.strength = 0.0
嘿,我有一个 world/Scene,里面有一个人,所以我决定制作一个物理场来充当重力。所以我可以使用 swift 毫无问题地对其进行编码,但是后来我 运行 该应用程序并且它一直给我错误的访问权限。没有这些代码行,我的 app/scenekit 游戏可以顺利运行任何帮助。请查看所附图片谢谢
代码:
// I declared field owner up at the top here
class GameViewController: UIViewController, ADBannerViewDelegate, SKPhysicsContactDelegate, SKSceneDelegate, SCNSceneRendererDelegate, SCNPhysicsContactDelegate{
var fieldOwner = SCNNode()
override func viewDidLoad() {
super.viewDidLoad()
//Force field to act as Gravity
fieldOwner = SCNNode()
fieldOwner.position = SCNVector3(x: 0, y: -5, z: -5)
let field: SCNPhysicsField = SCNPhysicsField.radialGravityField()
field.halfExtent = SCNVector3Make(100, 100, 100)
field.minimumDistance = 20.0
field.falloffExponent = 0
self.fieldOwner.physicsField!.strength = 0.0
self.fieldOwner.physicsField = field
scnView.scene!.rootNode.addChildNode(fieldOwner)
}
}
看起来您在设置之前正在访问 self.fieldOwner.physicsField
。尝试在本地 field
变量上设置强度:
改变
self.fieldOwner.physicsField!.strength = 0.0
到
field.strength = 0.0