【发布时间】:2018-01-01 05:02:54
【问题描述】:
【问题讨论】:
【问题讨论】:
您可以添加SCNPlane 并使用SCNLookAtConstraint 以使飞机始终看着相机。
您可以创建自定义材质并将其设置为 material properties 为:
一种颜色(UIColor 或 CGColor),指定材质表面的恒定颜色 一个数字(
图像(UIImage 或 CGImage),指定要映射到材质表面的纹理
- 核心动画层 (CALayer)
- 纹理(SKTexture、MDLTexture、MTLTexture 或 GLKTextureInfo)
- SpriteKit 场景 (SKScene)
您也可以使用 CoreAnimation 或 SpriteKit 显示动画内容,但是
SceneKit 不能使用已经在别处显示的层(例如,UIView 对象的支持层)
这是一个使用 SpriteKit 的示例:
例如:
let skScene = SKScene(size: CGSize(width: 200, height: 200))
skScene.backgroundColor = UIColor.clear
let rectangle = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 200, height: 200), cornerRadius: 10)
rectangle.fillColor = #colorLiteral(red: 0.807843148708344, green: 0.0274509806185961, blue: 0.333333343267441, alpha: 1.0)
rectangle.strokeColor = #colorLiteral(red: 0.439215689897537, green: 0.0117647061124444, blue: 0.192156866192818, alpha: 1.0)
rectangle.lineWidth = 5
rectangle.alpha = 0.4
let labelNode = SKLabelNode(text: "Hello World")
labelNode.fontSize = 20
labelNode.fontName = "San Fransisco"
labelNode.position = CGPoint(x:100,y:100)
skScene.addChild(rectangle)
skScene.addChild(labelNode)
例如
let plane = SCNPlane(width: 20, height: 20)
let material = SCNMaterial()
material.isDoubleSided = true
material.diffuse.contents = skScene
plane.materials = [material]
let node = SCNNode(geometry: plane)
scene.rootNode.addChildNode(node)
例如
labelNode.run(SKAction.repeatForever(SKAction.rotate(byAngle: .pi, duration: 2)))
【讨论】:
material.diffuse.contentsTransform = SCNMatrix4Translate(SCNMatrix4MakeScale(1, -1, 1), 0, 1, 0)。
可能值得一提的是,您还可以将其他一些东西用于内容...可以在此处找到列表... https://developer.apple.com/documentation/scenekit/scnmaterialproperty/1395372-contents
我尝试了上面答案中的代码,它运行良好,但降低了我的 FPS,因为我有很多节点需要它。而且 SKScene 可能很重。
我能够将 SKView 与 SKLabelNode 一起使用,但问题是文本不会在视觉上更新,我的猜测是我每次都必须调用 texture(from:) 并且我认为这就像慢 SKView 纹理(来自:) https://developer.apple.com/documentation/spritekit/skview/1520114-texture
我看到了另一种使用 CALayer 的方法,但我认为 id 在更改文本时遇到了同样的问题,所以我只使用了 SCNText。
另外值得一提的是 SCNBillboardConstraint 作为 LookatConstraint 的替代品 https://developer.apple.com/documentation/scenekit/scnbillboardconstraint
【讨论】: