Class

SKPhysicsJoint

An object which connects two physics bodies.

Overview

An 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.

Table 1

Joint classes implemented in Sprite Kit

Class Name

Description

SKPhysicsJointFixed

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.

SKPhysicsJointSliding

A sliding joint allows the two bodies to slide along a chosen axis.

SKPhysicsJointSpring

A spring joint connects the two bodies with a spring whose length is the initial distance between the two bodies.

SKPhysicsJointLimit

A limit joint imposes a maximum distance between the two bodies, as if they are connected by a rope.

SKPhysicsJointPin

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:

  1. Create two physics bodies.

  2. Attach the physics bodies to a pair of SKNode objects in the scene.

  3. Create a joint object using one of the subclasses listed in Table 1.

  4. If necessary, configure the joint object’s properties.

  5. Add the joint to the scene by calling the scene SKPhysicsWorld object’s add(_:) method.

Symbols

Inspecting Joint Properties

var bodyA: SKPhysicsBody

The first body connected by the joint.

var bodyB: SKPhysicsBody

The second body connected by the joint.

Measuring Force Effects Against the Anchor Point

var reactionForce: CGVector

The instantaneous reaction force currently being directed at the anchor point, in Newtons.

var reactionTorque: CGFloat

Instantaneous reaction torque currently being directed at the anchor point, in Newton-meters.

Relationships

Inherits From