【发布时间】:2019-09-20 07:29:03
【问题描述】:
我在加载我的应用程序时在我的视图中放置了多个 SCNNode。 在 touchesbegan 上,我正在删除任何被点击的节点。
到目前为止,所有这些都有效,因此我知道我的代码可以正常工作,但是仅添加 SCNParticleSystem 就会给我带来问题。
我在不工作的行旁边放了两颗星 (**)
// On tap
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// Register tap
let touch = touches.first!
// Get location
let location = touch.location(in: sceneView)
// Create a hit
let hitList = sceneView.hitTest(location, options: nil)
if let hitObject = hitList.first {
// Get node from hit
let node = hitObject.node
if node.name == target {
score += 3
playAudio(fileName: "two")
**let explosion = SCNParticleSystem(named: "stars.scnp", inDirectory: nil)
**node.addParticleSystem(explosion!)
node.removeFromParentNode()
// Async call
DispatchQueue.main.async {
node.removeFromParentNode()
self.scoreLabel.text = String(self.score)
}
}
}
}
如何将粒子附加到节点?
【问题讨论】:
-
您正在立即移除节点,因此不会看到粒子系统的任何效果
-
@TheInterloper 你是对的,我删除了删除节点的行,我的爆炸成功了!你知道我怎样才能让两者都发生吗?
-
在下面作为答案发布
标签: swift xcode arkit particle-system scnnode