问题
I create a macOS single window application and add a Sprite Particle System file with template Stars
. and the visual effect just like this:
And I want to add it to my viewController, as the guide of this answer, I got the result like this, and it was not which I desired:
override func viewDidLoad() { super.viewDidLoad() let scene = SCNScene() let particlesNode = SCNNode() let particleSystem = SCNParticleSystem(named: "Welcome", inDirectory: "") particlesNode.addParticleSystem(particleSystem!) scene.rootNode.addChildNode(particlesNode) skView.backgroundColor = .black skView.scene = scene }
So, I'm wondering what's wrong and what should I do?
Here is the demo repo: Link Here
The particle system itself is the standard "star" SceneKit particle system available in Xcode, with no changes.
回答1:
Well I made a little progress. If I swivel the camera around 180 degrees, I can see the stars receding, so we can tell that the particle system is running ok. In the default orientation, though, all I saw was blinking lights. So I think the particles are being generated with a Z position of 0, the same as the camera's.
If I move the system's node away from the camera
particlesNode.position = SCNVector3(0, 0, -20)
I still just see blinking lights. But if I click on the SCNView, the animation works correctly. I see stars coming at me.
I don't understand why I have to click the view to get it to work right. I tried isPlaying = true
but that made no difference.
来源:https://stackoverflow.com/questions/40803127/sprite-particle-system-animation-in-viewcontroller