Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a HUD on top of my Scenekit.scene

I'm experimenting with Swift and Scenekit. Building a Mac OS X app. It seems quite easy to get a 3d-scene working. But what is scene without some kind of 2D hi-score, radar display, speed indicator, etc? I would expect a SpriteKit-scene to seamlessly integrate into a SceneView but I don't find the documentation very clear about this..

The most obvious and only way I can think of is to position a SKView over a SceneView and render each separately. But is there a more elegant way?

like image 459
Ghis Avatar asked Jun 25 '14 21:06

Ghis


2 Answers

try

scnView.overlaySKScene = aSKScene;

(see SCNSceneRenderer.h) This is the recommended way. An alternative way is to make the SCNView layer backed and add child views or layers (but this is less efficient).

like image 52
Toyos Avatar answered Nov 17 '22 00:11

Toyos


To create a HUD, do something like the following:

// SKContainerOverlay is a class which inherits from SKScene

    SKContainerOverlay *skContainerOverlay = [[SKContainerOverlay alloc] initWithSize:self.sceneView.bounds.size];
    self.sceneView.overlaySKScene = skContainerOverlay;
    self.sceneView.overlaySKScene.hidden = NO;
    self.sceneView.overlaySKScene.scaleMode = SKSceneScaleModeResizeFill; // Make sure SKScene bounds are the same as our SCNScene
    self.sceneView.overlaySKScene.userInteractionEnabled = YES;

You can create all your SKLabelNode objects inside the custom SKContainerOverlay class.

like image 7
JaredH Avatar answered Nov 17 '22 00:11

JaredH