SKConstraint
An 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.
More...
Conforms To
Import Statement
Swift
import SpriteKit
ObjectiveC
@import SpriteKit;
Availability
Available in iOS 8.0 and later.

Creates a constraint that restricts the x coordinate of a node’s position.
Declaration
Swift
class func positionX(_
range
: SKRange) > SelfObjectiveC
+ (instancetype)positionX:(SKRange *)
range
Parameters
range
The range to restrict the coordinate to.
Return Value
A new constraint.
Discussion
Each time constraints are applied, the x coordinate of the node’s
position
property is clamped so that it lies inside the specified range.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

Creates a constraint that restricts the y coordinate of a node’s position.
Declaration
Swift
class func positionY(_
range
: SKRange) > SelfObjectiveC
+ (instancetype)positionY:(SKRange *)
range
Parameters
range
The range to restrict the coordinate to.
Return Value
A new constraint.
Discussion
Each time when constraints are applied, the y coordinate of the node’s
position
property is clamped so that it lies inside the specified range.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

Creates a constraint that restricts both coordinates of a node’s position.
Declaration
Parameters
xRange
The range to restrict the x coordinate to.
yRange
The range to restrict the y coordinate to.
Return Value
A new constraint.
Discussion
Each time constraints are applied, the node’s
position
property is clamped so that both coordinates lie inside the specified ranges.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

Creates a constraint that forces a node to rotate based on the position of another node.
Declaration
Parameters
node
The node that should be used to orient the node that this constraint is attached to.
radians
An offset that is added to the
zRotation
value after it is calculated.Return Value
A new constraint.
Discussion
Each time when constraints are applied, a new angle is calculated so that a line projected at this angle would point at the other node’s origin. This angle is added to the values specified in the
radians
property to create a new range. Finally, the node’szRotation
value is clamped to fit inside this range.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

Creates a constraint that forces a node to rotate to face a fixed point.
Declaration
Parameters
point
A point in the node’s parent’s coordinate system.
radians
An offset that is added to the
zRotation
value after it is calculated.Return Value
A new constraint.
Discussion
Each time when constraints are applied, a new angle is calculated so that a line projected at this angle would point at the target point. This angle is added to the values specified in the
radians
property to create a new range. Finally, the node’szRotation
value is clamped to fit inside this range.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.
See Also

Creates a constraint that forces a node to rotate to face a point in another node’s coordinate system.
Declaration
Parameters
point
A point in the
node
parameter’s coordinate system.node
The node whose coordinate system the point is specified in.
radians
An offset that is added to the
zRotation
value after it is calculated.Return Value
A new constraint.
Discussion
Each time when constraints are applied, a new angle is calculated so that a line projected at this angle would point at the target point. This angle is added to the values specified in the
radians
property to create a new range. Finally, the node’szRotation
value is clamped to fit inside this range.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

Creates a constraint that limits the orientation of a node.
Declaration
Swift
class func zRotation(_
zRange
: SKRange) > SelfObjectiveC
+ (instancetype)zRotation:(SKRange *)
zRange
Parameters
zRange
A range value that specifies the minimum and maximum values of the node’s
zRotation
property.Return Value
A new constraint.
Discussion
Each time when constraints are applied, the node’s
zRotation
property is clamped so that it is within the specified range.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

Creates a constraint that keeps a node within a certain distance of another node.
Declaration
Parameters
range
The range of allowed distances between the two nodes.
node
The target node used to calculate the distance.
Return Value
A new constraint.
Discussion
Each time when constraints are applied, a line is projected between the node’s position and the target node’s position. The distance between the two points is calculated, and if it lies outside the specified range, the node is pushed or pulled along this line until it lies within the range.
Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

Creates a constraint that keeps a node within a certain distance of a point.
Declaration
Parameters
range
The range of allowed distances between the node and the point.
point
A point in the coordinate system of the node’s parent that is used to calculate the distance.
Return Value
A new constraint.
Discussion
Each time when constraints are applied, a line is projected between the node’s position and the target point. The distance between the two points is calculated, and if it lies outside the specified range, the node is pushed or pulled along this line until it lies within the range.
Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.
See Also

Creates a constraint that keeps a node within a certain distance of a point in another node’s coordinate system.
Declaration
Parameters
range
The range of allowed distances.
point
The point to use as the target point.
node
The node whose coordinate system the point is specified in.
Return Value
A new constraint.
Discussion
Each time when constraints are applied, a line is projected between the node’s position and the target point. The distance between the two points is calculated, and if it lies outside the specified range, the node is pushed or pulled along this line until it lies within the range.
Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

referenceNode referenceNode
PropertyThe node whose coordinate system should be used to apply the constraint.
Discussion
The default value is
nil
, meaning that the coordinate system of the node’s parent is used to apply the constraint. If another node is specified, all positions are converted into this node’s coordinate system before the constraint is applied.Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.

A Boolean value that specifies whether the constraint is applied.
Declaration
Swift
var enabled: Bool
ObjectiveC
@property BOOL enabled
Import Statement
Swift
import SpriteKit
Availability
Available in iOS 8.0 and later.
Copyright © 2015 Apple Inc. All rights reserved. Terms of Use  Privacy Policy  Updated: 20140917