move sphere animation - SceneKit Swift Xcode

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

move sphere animation - SceneKit Swift Xcode

Bjorn Chin Fo Sieeuw

I want to make an animation in SceneKit in which the sphere is moving. I have the following code in Atoms.swift:

 

import Foundation

import SceneKit

 

class Atoms {

 

    class func carbonAtom()->SCNGeometry {

        var rootNode: SCNNode

        let carbonAtom = SCNSphere(radius: 1.70)

 

        carbonAtom.firstMaterial!.diffuse.contents = UIColor.darkGrayColor()

        carbonAtom.firstMaterial!.specular.contents = UIColor.whiteColor()

 

        let carbonNode = SCNNode(geometry: carbonAtom)

        self.rootNode.addChildNode(carbonNode)//error

        let moveUp = SCNAction.moveByX(0.0, y: 1.0, z: 0.0, duration: 1.0)

        carbonNode.runAction(moveUp)

 

        return carbonAtom

 

    }

 

}

The error in the line starting with self is:

'Atoms.Type' does not have a member named 'rootNode'. What does this mean and what do I have to do to make the sphere move?

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/1f390bbf-592f-448e-89fb-fd662120f43f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: move sphere animation - SceneKit Swift Xcode

Jens Alfke

On Jan 12, 2015, at 10:35 AM, Bjorn Chin Fo Sieeuw <[hidden email]> wrote:

'Atoms.Type' does not have a member named 'rootNode'. What does this mean and what do I have to do to make the sphere move?

It says your Atoms class doesn't have a rootNode method or property. 

You defined a local variable named rootNode in the carbonAtom() method. So either you should refer to it as just "rootNode", or you should move the declaration outside the method declaration so it becomes a property. (But even if it's a property, you can't refer to it from inside a class method, because there's no instance.)

—Jens

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/5C9C451B-6405-4E8A-A355-3A29871F7D28%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: move sphere animation - SceneKit Swift Xcode

Bjorn Chin Fo Sieeuw
In reply to this post by Bjorn Chin Fo Sieeuw
Now I tried

var rootNode: SCNNode  = SCNNode()

as a local variable, and it compiles. But the sphere does not move. I am trying to modify the code found here:

https://www.dropbox.com/sh/nt0hnw1tib0ppkh/AAAJMAkUQcck2F-r3VUKDd7Xa?dl=0


Op maandag 12 januari 2015 19:35:52 UTC+1 schreef Bjorn Chin Fo Sieeuw:

I want to make an animation in SceneKit in which the sphere is moving. I have the following code in Atoms.swift:

 

import Foundation

import SceneKit

 

class Atoms {

 

    class func carbonAtom()->SCNGeometry {

        var rootNode: SCNNode

        let carbonAtom = SCNSphere(radius: 1.70)

 

        carbonAtom.firstMaterial!.diffuse.contents = UIColor.darkGrayColor()

        carbonAtom.firstMaterial!.specular.contents = UIColor.whiteColor()

 

        let carbonNode = SCNNode(geometry: carbonAtom)

        self.rootNode.addChildNode(carbonNode)//error

        let moveUp = SCNAction.moveByX(0.0, y: 1.0, z: 0.0, duration: 1.0)

        carbonNode.runAction(moveUp)

 

        return carbonAtom

 

    }

 

}

The error in the line starting with self is:

'Atoms.Type' does not have a member named 'rootNode'. What does this mean and what do I have to do to make the sphere move?

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/c5d57a3a-e107-4715-a51e-b9b6abe31b2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: move sphere animation - SceneKit Swift Xcode

Bjorn Chin Fo Sieeuw
In reply to this post by Bjorn Chin Fo Sieeuw
Now I tried

var rootNode: SCNNode  = SCNNode()

as a local variable, and it compiles. But the sphere does not move. I am trying to modify the code found here:

https://www.dropbox.com/sh/nt0hnw1tib0ppkh/AAAJMAkUQcck2F-r3VUKDd7Xa?dl=0


Op maandag 12 januari 2015 19:35:52 UTC+1 schreef Bjorn Chin Fo Sieeuw:

I want to make an animation in SceneKit in which the sphere is moving. I have the following code in Atoms.swift:

 

import Foundation

import SceneKit

 

class Atoms {

 

    class func carbonAtom()->SCNGeometry {

        var rootNode: SCNNode

        let carbonAtom = SCNSphere(radius: 1.70)

 

        carbonAtom.firstMaterial!.diffuse.contents = UIColor.darkGrayColor()

        carbonAtom.firstMaterial!.specular.contents = UIColor.whiteColor()

 

        let carbonNode = SCNNode(geometry: carbonAtom)

        self.rootNode.addChildNode(carbonNode)//error

        let moveUp = SCNAction.moveByX(0.0, y: 1.0, z: 0.0, duration: 1.0)

        carbonNode.runAction(moveUp)

 

        return carbonAtom

 

    }

 

}

The error in the line starting with self is:

'Atoms.Type' does not have a member named 'rootNode'. What does this mean and what do I have to do to make the sphere move?

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/370adc95-e88e-4ddb-b3b2-376ae6f8732c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: move sphere animation - SceneKit Swift Xcode

Jens Alfke
In reply to this post by Bjorn Chin Fo Sieeuw
The code you're modifying is just supposed to create the scene nodes. There must be other code in the project that actually runs the animation. You can't run the animation from the file you're modifying because it doesn't know what scene the atoms are going to be added to.

—Jens

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/7EA984D4-AD97-4F78-B85D-50F3E16A0199%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.