我正在努力使用创建注释overlaySKScene
与此类似的东西(https://sketchfab.com/models/1144d7be20434e8387a2f0e311eca9b1# https://sketchfab.com/models/1144d7be20434e8387a2f0e311eca9b1#)。我跟着https://github.com/halmueller/ImmersiveInterfaces/tree/master/Tracking%20Overlay https://github.com/halmueller/ImmersiveInterfaces/tree/master/Tracking%20Overlay创建覆盖层。
但在提供的示例中,他们仅创建一个注释,并且它是静态的。我想根据我们拥有的子节点的数量动态创建多个注释,并且还应该能够将注释放置在相应子节点的顶部。如何实现这一目标?
我正在添加如下所示的叠加层,
sceneView.overlaySKScene = InformationOverlayScene(size: sceneView.frame.size)
其中 InformationOverlayScene 是SKScene
我在其中添加了两个childnodes
创建一个注释。
使用映射到子节点数组的注释精灵创建一个数组,然后执行如下操作:
func renderer(_ aRenderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
let scnView = self.view as! SCNView
//for each character
for var i in 0...inBattleChars.count-1 {
let healthbarpos = scnView.projectPoint(inBattleChars[i].position)
battleSKO.healthbars[i].position = CGPoint(x: CGFloat(healthbarpos.x), y: (scnView.bounds.size.height-10)-CGFloat(healthbarpos.y))
}
}
在渲染每一帧之前,这会更新 inBattleChars 中每个 SCNNode 的 SKSprite(在 healthBars 中)的位置。关键部分是projectPoint用于根据3D场景中的SCNNode获取SK叠加场景的2D位置。
为了防止不可见节点的注释显示(例如父对象背面的子节点),请使用 SCNRenderer 的nodesInsideFrustum(of:) 方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)