Contents

SKConstraint

A specification for constraining a node’s position or rotation.

Declaration

class SKConstraint

Mentioned in

Overview

An SKConstraint object describes a mathematical constraint on a node’s position or orientation. You attach constraints to nodes; after a scene processes any actions and physics interactions, it applies constraints attached to nodes in its node tree. Use constraints to ensure that certain relationships are true before the system renders a scene. For example, you might use a constraint to:

  • Change a node’s zRotation property so that it always points at another node or a position in the scene.

  • Keep a node within a specified distance of another node or a point in the scene.

  • Keep a node inside a specified rectangle.

  • Restrict the zRotation property of a node so that it has a more limited rotation range of motion.

To use constraints, create an NSArray object that contains one or more constraint objects and assign the array to a node’s constraints property. When the system evaluates a scene, it executes the constraints on a node in the order they appear in the constraints array.

You can’t change a constraint after you create it. However, you can selectively disable or enable a constraint by setting its enabled property. You can also use the referenceNode property to convert positions to the referenced coordinate system before applying the constraint.

Topics

Creating Position Constraints

Creating Orientation Constraints

Creating Distance Constraints

Controlling the Coordinate System Where a Constraint is Applied

Enabling and Disabling a Constraint

Initializers

See Also

Constraints