Group Group Group Group Group Group Group Group Group

Using custom Camera class in SceneKit

#1

Hey,

I am stuck on something and could use some help…
I have created a custom Camera class, I would like to add this class to my ViewController so I can load the same camera for all my levels.

I define the class as follows:

class GameCamera: SCNCamera {

let cameraNode: SCNNode!

override init() {
    cameraNode = SCNScene(named: "/GameAssets.scnassets/Camera.scn")?.rootNode.childNode(withName: "GameCamera", recursively: true)
    
    super.init()
}

func setup(scnView: SCNView) {
    scnView.scene?.rootNode.addChildNode(cameraNode)
    cameraNode.position = SCNVector3(x: 0, y: 0, z: 0)
    
}

}

In the ViewController I then declare a variable and initialise with the class

private var camera = GameCamera()

And i then set up the camera…

camera.setup(scnView: self.scnView)

The camera seems to load, but I can’t seem to view through it. So the class is there but maybe the actual camera object is not loaded??

#2

@chrislanguage Can you please help with this when you get a chance? Thank you - much appreciated! :]

closed #3

This topic was automatically closed after 166 days. New replies are no longer allowed.