0

Im getting an Error on the 4th line of code I attached a picture to this question that should explain everything its probably a quick fix but I've never seen it.

enter image description here

Code:

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

Below Is A picture of the errors I get when I do the suggested answers to this question

enter image description here

Extra Argument ??? Thanks almost there lol

enter image description here

Hamish
  • 78,605
  • 19
  • 187
  • 280
  • See [this Q&A](http://stackoverflow.com/questions/24213436/how-to-use-enumeratechildnodeswithname-with-swift-in-spritekit) – simply drop the explicit type annotations from the closure, and then use `stop.memory = true` to stop the enumeration. – Hamish Jul 30 '16 at 17:36
  • Ok But know i get any error on self.enumrateChildNodesWithName. to replace self I used "Guy", "GuyScene!.rootNode", "scnView.scene!" I updated me question –  Jul 30 '16 at 17:47
  • Don't use `enumerateChildNodesWithName`, use `enumerateChildNodesUsingBlock` – I was just linking to that Q&A as an example of how to input the closure (it's SpriteKit code, not SceneKit though). – Hamish Jul 30 '16 at 17:52
  • I updated my question at the bottom –  Jul 30 '16 at 17:59
  • Note that for future questions, please don't post pictures of code (as it makes is difficult for others to reproduce your problem) – simply copy and paste the relevant parts of your code into the question body itself (in this case you only needed to copy in paste the `enumerateChildNodesUsingBlock` call, along with the error message) – Hamish Jul 30 '16 at 18:15

1 Answers1

0

The simplest way to fix this problem is just to drop the explicit type annotations and let Swift infer them for you:

scene.rootNode.enumerateChildNodesUsingBlock({child, stop in

    // ...

    // to stop the enumeration (as stop is an UnsafeMutablePointer to an ObjCBool)
    stop.memory = true
})

You can also use trailing closure syntax to make the call look slightly neater:

scene.rootNode.enumerateChildNodesUsingBlock {child, stop in
    // ...
}
Hamish
  • 78,605
  • 19
  • 187
  • 280
  • animation = child(animationForKey: child.animationKeys[0]) Can not call value of non function type 'SCNNode'. Its refereeing to the "child" right after the equal sign –  Jul 30 '16 at 18:21
  • @HunterAllen This is a different problem to the question that you originally asked (meaning you should probably [ask a new question](http://stackoverflow.com/questions/ask)), but it looks like you've just confused the syntax for a function call – you probably want `child.animationForKey(child.animationKeys[0])`. – Hamish Jul 30 '16 at 18:40