【问题标题】:SceneKit Particle System not appearingSceneKit 粒子系统未出现
【发布时间】:2019-03-08 13:47:35
【问题描述】:

我正在尝试使用 Scenekit 中的粒子系统为火箭添加火焰。粒子文件看起来很好,我没有收到任何错误,但是当我运行应用程序时粒子没有出现。 reactor.scnp 和 spark.png 都位于 art.scnassets 文件夹以及主应用程序文件夹中。

  @objc func sceneTapped(recognizer: UITapGestureRecognizer) {
        let location = recognizer.location(in: sceneView)

        let hitResults = sceneView.hitTest(location, options: nil)
        if hitResults.count > 0 {
            let result = hitResults[0] as! SCNHitTestResult
            let node = result.node

            let physicsBody = SCNPhysicsBody(type: .dynamic, shape: nil)
            rocket.physicsBody = physicsBody
            let direction = SCNVector3(0, 3, 0)


            let rocketshipNode = rocket

            let reactorParticleSystem = SCNParticleSystem(named: "reactor.scnp", inDirectory: nil) //SCNParticleSystem(coder: "art.scnassets/reactor")
            print(reactorParticleSystem)
                let engineNode = rocket.childNode(withName: "node2", recursively: false)
            print(engineNode)

            // 3
            physicsBody.isAffectedByGravity = false
            physicsBody.damping = 0

            // 4
            let collider = [floor]
            reactorParticleSystem?.colliderNodes = collider as? [SCNNode]
            // 5
            engineNode?.addParticleSystem(reactorParticleSystem!)

            // 6
            let action = SCNAction.moveBy(x: 0, y: 0.3, z: 0, duration: 3)
            action.timingMode = .easeInEaseOut
            rocketshipNode!.runAction(action)



        }
    }

【问题讨论】:

  • engineNode 没有父节点。 rootNode?.addChildNode(engineNode)
  • @E.Coms 我收到错误“'SCNNode 类型的值?'没有成员'rootNode'"
  • rootNode来自scnscene。我的意思是engineNode没有父节点,离开函数域时会被移除。
  • 我的“reactorParticleSystem”也为零
  • 这意味着你没有得到“reactor.scnp”文件。

标签: swift scenekit particles particle-system


【解决方案1】:

不确定是什么问题,但我重新创建了粒子系统文件,它似乎工作正常。

【讨论】:

    猜你喜欢
    • 2023-03-30
    • 2019-05-28
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    相关资源
    最近更新 更多