Add joints to nodes in your scene.
Although you can make a lot of interesting games that use the physics systems already described, you can take your designs further by connecting physics bodies using joints. When the scene simulates the physics, it takes these joints into account when calculating how forces affect the bodies. The following illustration shows the types of joints you can use.
You add or remove joints using the physics world. When you create a joint, the points that connect the joint are always specified in the scene’s coordinate system. This may require you to first convert from node coordinates to scene coordinates before creating the joint.
Add a Joint to Nodes in Your Scene
To use a physics joint in your app, 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 types shown above.
If necessary, configure the joint object’s properties to define how the joint should operate.
Retrieve the scene’s
Call the physics world’s
The following code pins two nodes,
piston, together using a
SKPhysics joint. In this example, the node
pin is a child of
connecting. Because it is not an immediate child of the scene, its coordinates are converted to scene coordinates for use in initializing the joint.