附加到ARAnchor的SpriteKit SKLabelNode不会全屏显示或显示 [英] SpriteKit SKLabelNode attached to ARAnchor doesn't appear or appears fullscreen

查看:123
本文介绍了附加到ARAnchor的SpriteKit SKLabelNode不会全屏显示或显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将锚添加到我的场景视图的世界原始位置:

let configuration = ARWorldTrackingConfiguration()
sceneView.session.run(configuration)
sceneView.session.add(anchor: ARAnchor(name: "world origin", transform: matrix_identity_float4x4))
sceneView.presentScene(SKScene())

然后我选择在我的锚点位置显示SKLabelNode

func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? {
    // Create and configure a node for the anchor added to the view's session.
    let labelNode = SKLabelNode(text: "👾")
    labelNode.horizontalAlignmentMode = .center
    labelNode.verticalAlignmentMode = .center
    return labelNode;
}

当我运行应用程序并移动摄像头时,我注意到要么根本看不到节点(我只看到普通摄像头),要么看到整个屏幕是紫色的(好像标签节点的字体很大)。

我尝试添加labelNode.fontSize = 5,但仍然存在相同的问题。

如何使节点在SpriteKit场景中正确显示?

推荐答案

当我将我的代码与苹果默认的SpriteKit+ARKit示例应用程序进行比较时,主要的区别是行:

sceneView.presentScene(SKScene())

在他们的示例代码中,他们使用:

// Load the SKScene from 'Scene.sks'
if let scene = SKScene(fileNamed: "Scene") {
    sceneView.presentScene(scene)
}

它看起来像SKScene.sks的大小为750 x 1334,因此等效于:

sceneView.presentScene(SKScene(size: CGSize(width: 750, height: 1334)))

当我将代码更新到最后一行时(即给SKScene一个大小),一切都正常显示。然而,我不认为硬编码宽度和高度是正确的做法。我会问separate question关于这个问题。

这篇关于附加到ARAnchor的SpriteKit SKLabelNode不会全屏显示或显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆