Class

SKFieldNode

A node that applies physics effects to a portion of the scene.

Overview

There are many different kinds of field nodes that can be created, each with different effects. The Creating Field Nodes section lists the field types you can create using Sprite Kit, including a type that allows you to apply custom forces to physics bodies. Instantiate the appropriate kind of field node and then add it to the scene’s node tree.

When the scene simulates physics effects, a field node applies its effect to a physics body so long as the following things are true:

  • The field node is in the scene’s node tree.

  • The field node’s isEnabled property is true.

  • The physics body is attached to a node that is in the scene’s node tree.

  • The physics body is located inside the field node’s region (see region).

  • The physics body is not located inside the region of another field node whose isExclusive property is set to true.

  • A logical AND operation between the field node’s categoryBitMask property and the physics body’s fieldBitMask property results in a nonzero value.

Symbols

Creating Field Nodes

class func dragField()

Creates a field node that applies a force that resists the motion of physics bodies.

class func electricField()

Creates a field node that applies an electrical force proportional to the electrical charge of physics bodies.

class func linearGravityField(withVector: vector_float3)

Creates a field node that accelerates physics bodies in a specific direction.

class func magneticField()

Creates a field node that applies a magnetic force based on the velocity and electrical charge of the physics bodies.

class func noiseField(withSmoothness: CGFloat, animationSpeed: CGFloat)

Creates a field node that applies a randomized acceleration to physics bodies.

class func radialGravityField()

Creates a field node that accelerates physics bodies toward the field node.

class func springField()

Creates a field node that applies a spring-like force that pulls physics bodies toward the field node.

class func turbulenceField(withSmoothness: CGFloat, animationSpeed: CGFloat)

Creates a field node that applies a randomized acceleration to physics bodies.

class func velocityField(with: SKTexture)

Creates a field node that sets the velocity of physics bodies that enter the node’s area based on the pixel values of a texture.

class func velocityField(withVector: vector_float3)

Creates a field node that gives physics bodies a constant velocity.

class func vortexField()

Creates a field node that applies a perpendicular force to physics bodies.

class func customField(evaluationBlock: SKFieldForceEvaluator)

Creates a field node that calculates and applies a custom force to the physics body.

Determining Which Physics Bodies Are Affected by the Field

var isEnabled: Bool

A Boolean value that indicates whether the field is active.

var isExclusive: Bool

A Boolean value that indicates whether the field node should override all other field nodes that might otherwise affect physics bodies.

var region: SKRegion?

The area (relative to the node’s origin) that the field affects.

var minimumRadius: Float

The minimum value for distance-based effects.

var categoryBitMask: UInt32

A mask that defines which categories this field belongs to.

Configuring the Strength of the Field

var strength: Float

The strength of the field.

var falloff: Float

The exponent that defines the rate of decay for the strength of the field as the distance increases between the node and the physics body being affected.

Configuring Other Field Properties

These properties are associated with specific types of field nodes.

var animationSpeed: Float

The rate at which a noise or turbulence field node changes.

var smoothness: Float

The smoothness of the noise used to generate the forces.

var direction: vector_float3

The direction of a velocity field node.

var texture: SKTexture?

A normal texture that specifies the velocities at different points in a velocity field node.

Constants

SKFieldForceEvaluator

The definition for a custom block that processes a single physics body’s interaction with the field.

Relationships

Inherits From

Conforms To