Scene Kit Tutorial with Swift Part 5: Particle Systems

In this 5-part Scene Kit tutorial series, you’ll learn how to make your first 3D iOS game: a game like Fruit Ninja called Geometry Fighter! By Chris Language.

Leave a rating/review
Save for later
Share

Scene Kit Tutorial with Swift Part 5: Particle Systems

30 mins

Simulation Attributes

The simulation attributes manage the motion of particles over their lifetimes. This lets you manage their movement without having to use the physics engine:

• Life span: Specifies the lifetime of a particle in seconds. Set this to `1`, so that a single particle will only exist for a total time of a single second.
• Linear velocity: Specifies the linear velocity of the emitted particles. Set this to `0`, the particles are spawned with no direction or velocity.
• Angular velocity: Specifies the angular velocity of the emitted particles. Set this to `0`, the particles will not be spinning.
• Acceleration: Specifies the force vector applied to the emitted particles. Set this to `(x: 0, y: -5, z: 0)`, which is a downwards vector, simulating a soft gravity effect on the particles once spawned.
• Speed factor: A multiplier that sets the speed of the particle simulation. Set this to `1`, running the simulation at a normal speed.
• Stretch factor: A multiplier that stretches particles in their direction of motion. Set this to `0`, keeping the particle image un-stretched.

Image Attributes

The image attributes control the visual aspects of the particles. They also govern how the appearance of those particles can change over their lifetimes:

• Image: Specifies an image with which each particle will be rendered. Select the CircleParticle.png image, giving the particle its primary shape.
• Color: Sets the tint of the specified image. Set the color to White, giving the particle system a base color of white.
• Animate color: Causes particles to change color over their lifetimes. Un-check this, because the particle color is not going to change at all.
• Color variation: Adds a bit of randomness to the particle color. You can set this to `(h: 0, s: 0, b: 0, a: 0)`, because the particle color will not vary.
• Size: Specifies the size of the particles. Set this to `0.1`, so that the emitted particles are small in size.

Image Sequence Attributes

To create an animated image for your particles, you arrange each frame of the animation into a grid on a single image (like a sprite sheet in a game). Then you simply use that grid image as the image for your particle emitter. The image sequence attributes let you control the basic animation properties of the particle:

• Initial frame: Sets the first zero-based frame of the animation sequence. The zeroth frame corresponds to the top left image in the grid. You’re using a single frame image, so set this to `0`.
• Frame rate: Controls the rate of the animation in frames per second. Set this to `0`, it only applies when using an image containing multiple frames.
• Animation: Specifies the behaviour of the animation sequence. Repeat loops the animation, Clamp only plays once, and Auto Reverse plays from the start to the end, then back again. You can leave this on `Repeat`, it doesn’t matter when using a single frame image.
• Dimensions: Specifies the number of rows and columns in the animation grid. Set this to `(Rows: 1, Columns: 1)`, because you’re using a single frame image.

Rendering Attributes

The rendering attributes define how the render phase treats the particles:

• Blending: Specifies the blend mode of the renderer when drawing the particles into the scene. Set this to Alpha, which will use the image alpha channel information for transparency.
• Orientation: Controls the rotation of the particles. Set this to Billboard screen-aligned, which will keep the flat particles facing the camera view at all times, so you won’t notice that the particles are indeed flat images.
• Sorting: Sets the rendering order of the particles. This property works in conjunction with the blend mode and affects how the blending is applied. Set this to None, the particle system will not make use of sorting.
• Lighting: Controls whether Scene Kit applies lighting to the particles. Un-check this, so that the particle system ignores any lights in the scene.

Physics Attributes

The physics attributes let you specify how particles behave in the physics simulation:

• Affected by gravity: Causes the scene’s gravity to affect the particles. Un-check this, you don’t want the particle system to participate in the physics simulation.
• Affected by physics fields: Causes physics fields within the scene to affect the particles. Un-check this, you don’t want physics fields to have an effect on the particles.
• Die on Collision: Lets physics bodies in your scene collide and destroy the particles. Un-check this, you don’t want particles to be removed when they collide with node objects in the scene.
• Physics Properties: Basic physics properties that control the physics behaviour of the particles during the physics simulation. You can leave all these at their default values, because the particle system will not make use of this.

Life Cycle Attributes

The life cycle attributes let you control the overall life cycle of your particle system:

• Emission Duration: Controls the length of time that the emitter will emit new particles. Set this to `1`, which will activate the particle emitter for a total length of 1 second.
• Idle Duration: Looping particle systems emit particles for the specified emission duration, then become idle for the specified idle duration, after which the cycle repeats. Set this to `0`, the particle system will only emit once.
• Looping: Specifies whether the particle system emits particles once, as in an explosion, or continously, as a volcano would. Set this to Loops continuously, so that the emitter emits for as long as it can before it is removed from the scene again.

Phew! There are a lot of attributes to consider for a single particle system, but this gives you a lot of control to get the exact special effect you’re looking for.

If you diligently copied over the values from the screenshots to your particle system, you will have a system that represents the following effect:

If yours doesn’t look like this, try rotating the camera. It might also help to change the background color to a dark blue like you see here to make the particle system easier to see.

Author