iOS Developer Library

Developer

SpriteKit Framework Reference SKPhysicsJoint Class Reference

Options
Deployment Target:

On This Page
Language:

SKPhysicsJoint

Conforms To


Import Statement


Swift

import SpriteKit

Objective-C

@import SpriteKit;

Availability


Available in iOS 7.0 and later.

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 1Joint 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 addJoint: method.

  • bodyA bodyA Property

    The first body connected by the joint.

    Declaration

    Swift

    var bodyA: SKPhysicsBody!

    Objective-C

    @property(nonatomic, retain) SKPhysicsBody *bodyA

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • bodyB bodyB Property

    The second body connected by the joint.

    Declaration

    Swift

    var bodyB: SKPhysicsBody!

    Objective-C

    @property(nonatomic, retain) SKPhysicsBody *bodyB

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • The instantaneous reaction force currently being directed at the anchor point, in Newtons. (read-only)

    Declaration

    Swift

    var reactionForce: CGVector { get }

    Objective-C

    @property(nonatomic, readonly) CGVector reactionForce

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • Instantaneous reaction torque currently being directed at the anchor point, in Newton-meters. (read-only)

    Declaration

    Swift

    var reactionTorque: CGFloat { get }

    Objective-C

    @property(nonatomic, readonly) CGFloat reactionTorque

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.