Hi, I just wanted to display a SpriteKit Scene in a SCNPlane. So I set the the SCNMaterial contents to my SKScene, but instead of getting the scene I'm getting a grey plane. This is my code by the way:
var mainScene: SKScene {
let scene = Game()
scene.size = CGSize(width: 1024, height: 1024)
scene.scaleMode = .resizeFill
scene.backgroundColor = .purple
scene.view?.backgroundColor = .purple
scene.view?.allowsTransparency = false
return scene
}
func initMainScene() -> SceneView {
mainScene.view?.isPaused = false
let scene = SCNScene()
let mainSceneMaterial = SCNMaterial()
mainSceneMaterial.normal.contents = mainScene
mainSceneMaterial.isDoubleSided = true
let planeGeometry = SCNPlane(width: 1, height: 1)
planeGeometry.materials = [mainSceneMaterial]
let plane: SCNNode = SCNNode(geometry: planeGeometry)
let camera: SCNNode = SCNNode()
camera.name = "Camera"
camera.camera = SCNCamera()
camera.position = SCNVector3(x: 0.0, y: 0.0, z: 4.0)
let light: SCNNode = SCNNode()
light.light = SCNLight()
light.light!.type = .omni
light.position = SCNVector3(x: 1.5, y: 1.5, z: 1.5)
scene.rootNode.addChildNode(camera)
scene.rootNode.addChildNode(light)
scene.rootNode.addChildNode(plane)
return SceneView(
scene: scene,
pointOfView: scene.rootNode.childNode(withName: "Camera", recursively: false),
options: []
)
}
Here is the screenshot:
Also, my SpriteKit scene has touchesBegan
and touchesMoved
functions implemented, will those events still work if I embed the scene in the SCNMaterial?
Thanks very much 🙏