Adding particles
As the icing on the cake, we will include a rain particle effect. To create a particle effect in SceneKit, go to File | New and, under Resource, select SceneKit Particle system. Click Next and, on the next screen, select Rain from the Particle System Template dropdown. Click Next and give the file a name. I called it rain
. Now you will have a rain.scnp
and spark.png
file in the project.
Add the following code at the end of the init
function of the GameSCNScene
class:
// add particle system let rain = SCNParticleSystem(named: "rain", inDirectory: nil) rain!.warmupDuration = 10 let particleEmitterNode = SCNNode() particleEmitterNode.position = SCNVector3(0, 100, 0) particleEmitterNode.addParticleSystem(rain!) self.rootNode.addChildNode(particleEmitterNode)
We create a new constant called rain
, assign SCNParticleSystem
to it, and provide the...