2

I am trying to add a SCNView on top of a SKView.

My hierarchy begins with a UIViewController. From there I present a SKScene on top of the UIViewController's view. Then I had added a few layers of SKSpriteNodes.

Visually speaking, I want to add a SCNView on top of the top layer of SKSpriteNodes for me to display a row of SCNBoxes.

Is there any way for me to do this aside from creating another UIViewController, adding all of my components on top of that new controller, then adding it on top of my currently existing ViewController?

I would appreciate a solution in Swift code, but I am able to read/write Objective-C, I just don't want to mix any Swift with Objective-C as I haven't needed to use any for my current project.

tuledev
  • 10,177
  • 4
  • 29
  • 49

1 Answers1

3

If you want to render 3D SceneKit content in a SpriteKit view, use SK3DNode. Then you get both the SK and SCN renderers cooperating to draw into the same OpenGL context (or Metal drawable), instead of trying to composite the output of two separate rendering pipelines at the UIKit level.

rickster
  • 124,678
  • 26
  • 272
  • 326
  • Thank you very much for this solution. It took me changing only one line of my code to get everything working (making the switch from SCNView to SK3DNode). – marionthefourth Aug 25 '15 at 22:37
  • Is the opposite possible, rendering an SKView as a material/texture on a plane in SceneKit? not as overlay – Confused Nov 15 '16 at 07:34
  • I kind of remember seeing this somewhere, but have spent 30 minutes googling, and reading and finding nothing. I could be stupid. – Confused Nov 15 '16 at 07:35
  • Not an SKView, but you can set an SKScene as a [material property's contents](https://developer.apple.com/reference/scenekit/scnmaterialproperty). I describe that a bit in [this answer](http://stackoverflow.com/a/25596862/957768). – rickster Nov 15 '16 at 14:49