【发布时间】:2017-08-03 04:23:30
【问题描述】:
我有一个 ARKit Spritekit 项目,我想为每个 ARAnchor 显示不同的图像。
我对匹配我添加到每个 ARAnchor 的 SKSpriteNode 图像的最佳方式有点困惑,因为SKScene Scene 类和视图控制器之间存在一些控制反转。
我在 Scene.swift 中添加锚点,并在视图控制器中处理委托方法。
func view(_ view: ARSKView, nodeFor anchor: ARAnchor) -> SKNode? {
// Create and configure a node for the anchor added to the view's session.
// this image url needs to be dynamic and vary for each node
let imageURL = "https://farm1.staticflickr.com/[SOMEID].jpg"
let url = URL(string: imageURL)
let data = try? Data(contentsOf: url!)
let theImage = UIImage(data: data!)
let Texture = SKTexture(image: theImage!)
return SKSpriteNode(texture: Texture)
}
我的问题是:我应该如何传递动态图像信息?
- 当我将锚点添加到 Scene.swift 中的
ARSKView时,我可以将ARAnchor子类化并在自定义锚点类中设置 imageUrl - 我是否应该插入
ARAnchor而不是从 Scene.swift 而是从视图控制器 - 然后以某种方式保持指向ARAnchor和 SKSpriteNode 的链接?
【问题讨论】: