A specification for constraining a node's position or rotation.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
SKConstraint object describes a mathematical constraint on a node’s position or orientation. Constraints are attached 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 a scene is rendered. For example, you might use a constraint to:
Change a node’s
zproperty 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.
zproperty 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 scene is evaluated, the constraints on a node are executed in the order they appear in the
Once created, a constraint can’t be changed. However, you can selectively disable or enable a constraint by setting its
enabled property. You can also use the
reference property to convert positions to the referenced coordinate system before applying the constraint.