2d叠加元素无法在场景套件场景上渲染

时间:2015-05-19 20:41:14

标签: swift sprite-kit overlay scenekit

我在场景套件场景中使用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)
    }
}

从我在这里看到的,代码写得正确。图像正在加载,但它不会在场景中的三维元素上渲染。

1 个答案:

答案 0 :(得分:0)

我过早地问了这个问题。根据我的研究,SKScene需要成为一个单独的类。我犯了一个小学生的错误。