在spritekit中访问sk3dnode

时间:2018-10-18 00:15:03

标签: swift scenekit

我正在尝试制作一个spritekit应用程序,该应用程序中将嵌入一个小型3D场景工具箱。我希望能够在我的touchesbegan函数中更改3-d scenekit对象的属性。有人可以帮我吗?谢谢!

这是我的代码:

import SpriteKit
import GameplayKit

class GameScene: SKScene {
// var scnScene: SCNScene
override func didMove(to view: SKView) {
    let redNode = SKShapeNode(circleOfRadius: 50.0)
    redNode.fillColor = UIColor.red
    redNode.position = CGPoint(x: 0, y: -200)
    self.addChild(redNode)
    let scnScene: SCNScene = {
        let scnScene = SCNScene()

        let torusGeometry = SCNTorus(ringRadius: 10, pipeRadius: 3)
        torusGeometry.name = "torusG"
        torusGeometry.firstMaterial?.diffuse.contents = UIColor.red
        let torusNode = SCNNode(geometry: torusGeometry)
        torusNode.name = "torusN"
        torusNode.eulerAngles = SCNVector3(x: Float(CGFloat.pi / 2), y: 0, z: 0)
        scnScene.rootNode.addChildNode(torusNode)
        return scnScene
    }()

    let node = SK3DNode(viewportSize: CGSize(width: 200, height: 200))
    node.scnScene = scnScene
    node.name = "3d"
    self.addChild(node)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    print("touch")
    // let mynode: SCNTorus = childNode(withName: "torusG") as SCNTorus
    let my3d: SK3DNode = childNode(withName: "3d") as! SK3DNode
    print(my3d.name)

    // change color of torus here???

}

}

0 个答案:

没有答案