I've got a Game
@StateObject
in my app that's passed to my main ContentView
. I'm trying to figure out how best create a SCNSceneRendererDelegate
instance that has a reference to the Game
state, and then pass that to the SceneView
inside my ContentView
.
I'm trying to do it like this, but obviously this doesn't work because self
isn't available at init time:
struct
ContentView : View
{
let game : Game
var scene = SCNScene(named: "art.scnassets/ship.scn")
var cameraNode : SCNNode? { self.scene?.rootNode.childNode(withName: "camera", recursively: false) }
var rendererDelegate = RendererDelegate(game: self.game) // Cannot find 'self' in scope
var
body: some View
{
SceneView(scene: self.scene,
pointOfView: self.cameraNode,
delegate: self.rendererDelegate)
}
}
The intent is that in my renderer delegate, I'll update my game's simulation state. Because my game state is an ObservableObject
, everything else (I have a bunch of SwiftUI) should update.