gpt4 book ai didi

swift - enumerateChildNodesUsingBlock 调用时出现 "Cannot convert value"错误

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

我在第四行代码上遇到错误,我在这个问题上附上了一张图片,应该可以解释一切,这可能是一个快速修复,但我从未见过它。

enter image description here

代码:

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

下面是我在执行此问题的建议答案时遇到的错误的图片

enter image description here

额外的论据???谢谢,差不多了,哈哈

enter image description here

最佳答案

解决此问题的最简单方法就是删除显式类型注释并让 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
// ...
}

关于swift - enumerateChildNodesUsingBlock 调用时出现 "Cannot convert value"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38676684/

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