我在场景套件场景中使用SKScene作为叠加层,但是当我向SKScene添加子节点时,它不会渲染到屏幕上。这是我的代码(截断):
import SceneKit
import SpriteKit
class GameViewController {
var scene = SCNScene()
var overlay = SKScene()
var expand = SKSpriteNode(imageNamed: "expand")
var trash = SKSpriteNode(imageNamed: "trash")
var palette = SKSpriteNode(imageNamed: "palette")
override func viewDidLoad() {
super.viewDidLoad()
// set up scene
let sceneView = view as! SCNView
sceneView.backgroundColor = SKColor.blackColor()
sceneView.autoenablesDefaultLighting = true
sceneView.showsStatistics = false
setupScene()
sceneView.scene = scene
sceneView.pointOfView = cameraNode
sceneView.overlaySKScene = overlay
setupEnvironment()
setupHud()
}
func setupHud() {
var sizeOfModifiers = (expand.frame.size.width + trash.frame.size.width + palette.frame.size.width) / 2
trash.anchorPoint = CGPointMake(0, 0)
palette.anchorPoint = CGPointMake(0, 0)
expand.anchorPoint = CGPointMake(0, 0)
trash.position = CGPointMake((view.frame.width / 2) - sizeOfModifiers, 0)
palette.position = CGPointMake(trash.position.x + trash.frame.size.width, 0)
expand.position = CGPointMake(palette.position.x + trash.frame.size.width, 0)
overlay.addChild(trash)
overlay.addChild(palette)
overlay.addChild(expand)
}
}
从我在这里看到的,代码写得正确。图像正在加载,但它不会在场景中的三维元素上渲染。
答案 0 :(得分:0)