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

心不动则不痛 提交于 2019-12-03 12:11:54

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).

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.

As @Toyos said above, you can use

scnView.overlaySKScene = aSKScene

to superimpose the SKScene on your SCNView.

However, when I tried this in Swift, I found that the overlaySKScene property only becomes visible if you include an import SpriteKit statement.

Pierre

As @Toyos answered, it is simple to day using scnView.overlaySKScene. If you want an example you can check how Apple did it in their Bananas demo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!