An object which connects two physics bodies.
- iOS 8.0+
- macOS 10.10+
- tvOS 9.0+
- watchOS 3.0+
SKPhysicsJoint object connects two physics bodies so that they are simulated together by the physics world. You never instantiate objects of this class directly; instead, you instantiate one of the subclasses that defines the kind of joint you want to make. This class implements the common properties of the joint classes provided by Sprite Kit.
Table 1 describes the kinds of joints you can create in Sprite Kit.
A fixed joint fuses the two bodies together at a reference point. Fixed joints are useful for creating complex shapes that can be broken apart later.
A sliding joint allows the two bodies to slide along a chosen axis.
A spring joint connects the two bodies with a spring whose length is the initial distance between the two bodies.
A limit joint imposes a maximum distance between the two bodies, as if they are connected by a rope.
A pin joint allows the two bodies to independently rotate around the anchor point as if pinned together.
To use a physics joint, you follow these steps:
Create two physics bodies.
Attach the physics bodies to a pair of
SKNodeobjects in the scene.
Create a joint object using one of the subclasses listed in Table 1.
If necessary, configure the joint object’s properties.