Class

CAEmitterLayer

A layer that emits, animates, and renders a particle system.

Declaration

@interface CAEmitterLayer : CALayer

Overview

The particles, defined by instances of CAEmitterCell, are drawn above the layer’s background color and border.

Listing 1 shows how to set up a simple point (the default emitterShape is kCAEmitterLayerPoint) particle emitter. It uses an image named RadialGradient.png as the cell contents and, by setting the emitter cell's emissionRange to 2 x pi, the particles are emitted in all directions.

Listing 1

Creating a simple particle system

let emitterLayer = CAEmitterLayer()
    
emitterLayer.emitterPosition = CGPoint(x: 320, y: 320)
    
let cell = CAEmitterCell()
cell.birthRate = 100
cell.lifetime = 10
cell.velocity = 100
cell.scale = 0.1
    
cell.emissionRange = CGFloat.pi * 2.0
cell.contents = UIImage(named: "RadialGradient.png")!.cgImage
    
emitterLayer.emitterCells = [cell]
    
view.layer.addSublayer(emitterLayer)

Topics

Specifying Particle Emitter Cells

emitterCells

The array emitter cells attached to the layer.

Emitter Geometry

renderMode

Defines how particle cells are rendered into the layer.

emitterPosition

The position of the center of the particle emitter. Animatable.

emitterShape

Specifies the emitter shape.

emitterZPosition

Specifies the center of the particle emitter shape along the z-axis. Animatable.

emitterDepth

Determines the depth of the emitter shape.

emitterSize

Determines the size of the particle emitter shape. Animatable.

Emitter Cell Attribute Multipliers

Emitter cell attribute multipliers only affect newly created particles, leaving existing particles unchanged.

For example, if your emitter has its scale multiplier set to 1 (the default) and, after it has emitted a number of particles, your code sets it to 2, particles already on screen are unaffected and remain the same size. Only newly spawned particles will be affected by the change and appear twice as large as their siblings.

scale

Defines a multiplier applied to the cell-defined particle scale.

seed

Specifies the seed used to initialize the random number generator.

spin

Defines a multiplier applied to the cell-defined particle spin. Animatable.

velocity

Defines a multiplier applied to the cell-defined particle velocity. Animatable.

birthRate

Defines a multiplier that is applied to the cell-defined birth rate. Animatable

emitterMode

Specifies the emitter mode.

lifetime

Defines a multiplier applied to the cell-defined lifetime range when particles are created. Animatable.

preservesDepth

Defines whether the layer flattens the particles into its plane.

Constants

Emitter Shape

The emission shape is a one, two or three dimensional shape that defines where the emitted particles originate. The shapes are defined by a subset of emitterPosition, emitterZPosition, emitterSize and emitterDepth properties.

Emitter Modes

These constants specify the possible emitter modes. They are used by the emitterMode property.

Emitter Render Order

These constants specify the order that emitter cells are composited. They are used by the renderMode property.

Relationships

Inherits From

See Also

Particle Systems

CAEmitterCell

The definition of a particle emitted by a CAEmitterLayer.