我在第4行代码上遇到错误我在这个问题上添加了一张图片,应该解释一切可能是一个快速修复,但我从未见过它。
代码:
let GuyScene = SCNScene(named: "art.scnassets/TestMan1.scn")
let Guy: SCNNode = GuyScene!.rootNode.childNodeWithName("Man", recursively: true)!
let collisionCapsuleRadius2 = CGFloat(0.1)
let collisionCapsuleHeight2 = CGFloat(0.1)
Guy.position = SCNVector3(x: -30.0, y: 30.0, z: 0.0)
Guy.scale = SCNVector3Make(5, 5, 5)
Guy.rotation = SCNVector4Make(0, 1, 0, 1 )
//----Giveing it a physics---------
Guy.physicsBody = SCNPhysicsBody(type: .Dynamic, shape:SCNPhysicsShape(geometry: SCNCapsule(capRadius: collisionCapsuleRadius2, height: collisionCapsuleHeight2), options:nil))
Guy.physicsBody?.affectedByGravity = true
Guy.physicsBody?.friction = 0 //
Guy.physicsBody?.restitution = 1 //bounceness of the object
Guy.physicsBody?.angularDamping = 1 // rotationess
Guy.physicsBody?.mass = 1
Guy.physicsBody?.rollingFriction = 0
GuyScene!.rootNode.addChildNode(Guy)
scnView.scene!.rootNode.addChildNode(Guy)
func loadAnimationFromSceneNamed(path: String) -> CAAnimation {
var scene: SCNScene = SCNScene(named: path )!
var animation: CAAnimation? = nil
scene.rootNode.enumerateChildNodesUsingBlock({(child: SCNNode, stop: Bool) -> Void in
if child.animationKeys.count > 0 {
animation = child(animationForKey: child.animationKeys[0])
stop = true
}
})
return animation!
}
var scenePath: String = "art.scnassets/Animation1.scn"
var thisAnimation: CAAnimation = loadAnimationFromSceneNamed(scenePath)
var timer = NSTimer.scheduledTimerWithTimeInterval(1.5, target: self, selector: "Start", userInfo: nil, repeats: true)
func Start() {
Guy.addAnimation(thisAnimation, forKey: "thisAnimationKey")
}
下面是我对这个问题的建议答案时得到的错误的图片
额外的争论???非常感谢大声笑
答案 0 :(得分:0)
解决此问题的最简单方法是删除显式类型注释,让Swift为您推断:
scene.rootNode.enumerateChildNodesUsingBlock({child, stop in
// ...
// to stop the enumeration (as stop is an UnsafeMutablePointer to an ObjCBool)
stop.memory = true
})
您还可以使用trailing closure syntax使通话看起来更整洁:
scene.rootNode.enumerateChildNodesUsingBlock {child, stop in
// ...
}