iOS Developer Library

Developer

SpriteKit Framework Reference SKPhysicsBody Class Reference

Options
Deployment Target:

On This Page
Language:

SKPhysicsBody

An SKPhysicsBody object is used to add physics simulation to a node. When a scene processes a new frame, it performs physics calculations on physics bodies attached to nodes in the scene. These calculations include gravity, friction, and collisions with other bodies. You can also apply your own forces and impulses to a body. After the scene completes these calculations, it updates the positions and orientations of the node objects.

To add physics to a node, create and configure an SKPhysicsBody object and then assign it to the physicsBody property of the SKNode object. A physics body must be associated with a node object before you apply forces or impulses to it.

Sprite Kit supports two kinds of physics bodies, volume-based bodies and edge-based bodies. When you create a physics body, its kind, size, and shape are determined by the constructor method you call. An edge-based body does not have mass or volume and is unaffected by forces or impulses in the system. Edge-based bodies are used to represent volume-less boundaries or hollow spaces in your physics simulation. In contrast, volume-based bodies are used to represent objects with mass and volume. The dynamic property controls whether a volume-based body is affected by gravity, friction, collisions with other objects, and forces or impulses you directly apply to the object.

The SKPhysicsBody class defines the physical characteristics for the body when it is simulated by the scene. For volume-based bodies, the most important property is the mass property. A volume-based body is assumed to have a uniform density. You can either set the mass property directly, or you can set the body’s density property and let the physics body calculate its own mass. All values in Sprite Kit are specified using the International System of Units (SI units). The actual forces and mass values are not important so long as your game uses consistent values.

When you design a game that uses physics, you define the different categories of physics objects that appear in the scene. You define up to 32 different categories of physics bodies, and a body can be assigned to as many of these categories as you want. In addition to declaring its own categories, a physics body also declares which categories of bodies it interacts with. See Working with Collisions and Contacts. You use a similar mechanism to declare which physics field nodes (SKFieldNode) can affect the physics body.

For a volume-based body, you can dynamically control how the body is affected by forces or collisions. See Defining How Forces Affect a Physics Body.

Other Related Physics Classes

A scene’s physicsWorld property holds an SKPhysicsWorld object that provides physics characteristics that affect the entire scene.

You can use fields to apply forces to a set of physics bodies or to change their velocities. See SKFieldNode Class Reference.

You can connect physics bodies together using joints. See SKPhysicsJoint Class Reference.

Inheritance


Conforms To


Import Statement


Swift

import SpriteKit

Objective-C

@import SpriteKit;

Availability


Available in iOS 7.0 and later.
  • Creates a circular physics body centered on the owning node’s origin.

    Declaration

    Swift

    init(circleOfRadius r: CGFloat) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithCircleOfRadius:(CGFloat)r

    Parameters

    r

    The radius of the circle.

    Return Value

    A new volume-based physics body.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Creates a circular physics body centered on an arbitrary point.

    Declaration

    Swift

    init(circleOfRadius r: CGFloat, center center: CGPoint) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithCircleOfRadius:(CGFloat)r center:(CGPoint)center

    Parameters

    r

    The radius of the circle.

    center

    The origin of the circle in the owning node’s coordinate system.

    Return Value

    A new volume-based physics body.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.1 and later.

  • Creates a rectangular physics body centered on the owning node’s origin.

    Declaration

    Swift

    init!(rectangleOfSize s: CGSize) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithRectangleOfSize:(CGSize)s

    Parameters

    s

    The size of the rectangle.

    Return Value

    A new volume-based physics body.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Creates a rectangular physics body centered on an arbitrary point.

    Declaration

    Swift

    init!(rectangleOfSize s: CGSize, center center: CGPoint) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithRectangleOfSize:(CGSize)s center:(CGPoint)center

    Parameters

    s

    The size of the rectangle.

    center

    The center of the square in the owning node’s coordinate system.

    Return Value

    A new volume-based physics body.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.1 and later.

  • Creates a physics body by performing a union of a group of volume-based physics bodies.

    Declaration

    Swift

    init(bodies bodies: [AnyObject]) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithBodies:(NSArray *)bodies

    Parameters

    bodies

    An array of SKPhysicsBody objects. The objects must be volume-based physics bodies. (You may not use a compound body created using this method in the array.)

    Return Value

    A new compound-physics body.

    Discussion

    The shapes of the physics bodies passed into this method are used to create a new physics body whose covered area is the union of the areas of its children. These areas do not need to be contiguous. If there is space between two parts, other bodies may be able to pass between these parts. However, the physics body is treated as a single connected body, meaning that a force or impulse applied to the body affects all of the pieces as if they are held together with an indestructible frame.

    The properties on the children, such as mass or friction, are ignored. Only the shapes of the child bodies are used.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.1 and later.

  • Creates a polygon-shaped physics body.

    Declaration

    Swift

    init!(polygonFromPath path: CGPath!) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithPolygonFromPath:(CGPathRef)path

    Parameters

    path

    A convex polygonal path with counterclockwise winding and no self intersections. The points are specified relative to the owning node’s origin.

    Return Value

    A new volume-based physics body.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Creates a physics body from the contents of a texture.

    Declaration

    Swift

    init!(texture texture: SKTexture!, size size: CGSize) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithTexture:(SKTexture *)texture size:(CGSize)size

    Parameters

    texture

    The texture to convert into a physics body.

    size

    The size of the physics body to return.

    Return Value

    A new volume-based physics body.

    Discussion

    Use this method when your sprite has a shape that you want replicated in its physics body. The texture is scaled to the new size and then analyzed. A new physics body is created that includes all of the texels in the texture that have a nonzero alpha value. The shape of this body attempts to strike a good balance between performance and accuracy. For example, fine details may be ignored if keeping them would cause a significant performance penalty.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • Creates a physics body from the contents of a texture. Only texels that exceed a certain transparency value are included in the physics body.

    Declaration

    Swift

    init!(texture texture: SKTexture!, alphaThreshold alphaThreshold: Float, size size: CGSize) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithTexture:(SKTexture *)texture alphaThreshold:(float)alphaThreshold size:(CGSize)size

    Parameters

    texture

    The texture to analyze.

    alphaThreshold

    The minimum alpha value for texels that should be part of the new physics body.

    size

    The size of the physics body to return.

    Return Value

    A new volume-based physics body.

    Discussion

    Use this method when your sprite has a shape that you want replicated in its physics body. The texture is scaled to the new size and then analyzed. A new physics body is created that includes all of the texels in the texture whose alpha values equal or exceed the alphaThreshold parameter. The shape of this body attempts to strike a good balance between performance and accuracy. For example, fine details may be ignored if keeping them would cause a significant performance penalty.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • Creates an edge loop from a rectangle.

    Declaration

    Swift

    init(edgeLoopFromRect rect: CGRect) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithEdgeLoopFromRect:(CGRect)rect

    Parameters

    rect

    The rectangle that defines the edges. The rectangle is specified relative to the owning node’s origin.

    Return Value

    A new edge-based physics body.

    Discussion

    An edge has no volume or mass and is always treated as if the dynamic property is equal to NOfalse. Edges may only collide with volume-based physics bodies.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Creates an edge between two points.

    Declaration

    Swift

    init(edgeFromPoint p1: CGPoint, toPoint p2: CGPoint) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithEdgeFromPoint:(CGPoint)p1 toPoint:(CGPoint)p2

    Parameters

    p1

    The starting point for the edge, relative to the owning node’s origin.

    p2

    The ending point for the edge, relative to the owning node’s origin.

    Return Value

    A new edge-based physics body.

    Discussion

    An edge has no volume or mass and is always treated as if the dynamic property is equal to NOfalse. Edges may only collide with volume-based physics bodies.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Creates an edge loop from a path.

    Declaration

    Swift

    init(edgeLoopFromPath path: CGPath!) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithEdgeLoopFromPath:(CGPathRef)path

    Parameters

    path

    A Core Graphics path. The points are specified relative to the owning node’s origin. The path must not intersect itself.

    Return Value

    A new edge-based physics body.

    Discussion

    If the path is not already closed, a loop is automatically created by joining the last point to the first.

    An edge has no volume or mass and is always treated as if the dynamic property is equal to NOfalse. Edges may only collide with volume-based physics bodies.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Creates an edge chain from a path.

    Declaration

    Swift

    init(edgeChainFromPath path: CGPath!) -> SKPhysicsBody

    Objective-C

    + (SKPhysicsBody *)bodyWithEdgeChainFromPath:(CGPathRef)path

    Parameters

    path

    A Core Graphics path. The points are specified relative to the owning node’s origin. The path must not intersect itself.

    Return Value

    A new edge-based physics body.

    Discussion

    An edge has no volume or mass and is always treated as if the dynamic property is equal to NOfalse. Edges may only collide with volume-based physics bodies.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A Boolean value that indicates whether this physics body is affected by the physics world’s gravity and the gravity exerted by any physics fields in the scene.

    Declaration

    Swift

    var affectedByGravity: Bool

    Objective-C

    @property(nonatomic, assign) BOOL affectedByGravity

    Discussion

    The physics world’s gravity property defines the gravitational forces applied to volume-based bodies in the scene. The default value is YEStrue. This property is ignored on edge-based bodies, which are already unaffected by gravity.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A Boolean value that indicates whether the physics body is affected by angular forces and impulses applied to it.

    Declaration

    Swift

    var allowsRotation: Bool

    Objective-C

    @property(nonatomic) BOOL allowsRotation

    Discussion

    The default value is YEStrue. This property is ignored on edge-based bodies, which are unaffected by forces in the system.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • dynamic dynamic Property

    A Boolean value that indicates whether the physics body is moved by the physics simulation.

    Declaration

    Swift

    var dynamic: Bool

    Objective-C

    @property(nonatomic, getter=isDynamic) BOOL dynamic

    Discussion

    The default value is YEStrue. If the value is NOfalse, the physics body ignores all forces and impulses applied to it. This property is ignored on edge-based bodies; they are automatically static.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • mass mass Property

    The mass of the body in kilograms.

    Declaration

    Swift

    var mass: CGFloat

    Objective-C

    @property(nonatomic) CGFloat mass

    Discussion

    The actual unit is arbitrary as long as relative masses of objects are consistent throughout the game. The mass of the body affects its momentum as well as how forces are applied to the object.

    The mass and density properties are interrelated. When you change the value of either property, the other property’s value is automatically recalculated to be consistent. The default value is based on the size of the physics body and the body’s default density.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    density

  • density density Property

    The density of the object in kilograms per square meter.

    Declaration

    Swift

    var density: CGFloat

    Objective-C

    @property(nonatomic) CGFloat density

    Discussion

    The actual unit is arbitrary as long as relative masses of objects are consistent throughout the game.

    The mass and density properties are interrelated. When you change the value of either property, the other property’s value is automatically recalculated to be consistent.

    The default value is 1.0.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    mass

  • area area Property

    The area covered by the body. (read-only)

    Declaration

    Swift

    var area: CGFloat { get }

    Objective-C

    @property(nonatomic, readonly) CGFloat area

    Discussion

    This property is used in conjunction with the density property to calculate the body’s mass.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • friction friction Property

    The roughness of the surface of the physics body.

    Declaration

    Swift

    var friction: CGFloat

    Objective-C

    @property(nonatomic) CGFloat friction

    Discussion

    This property is used to apply a frictional force to physics bodies in contact with this physics body. The property must be a value between 0.0 and 1.0. The default value is 0.2.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • The bounciness of the physics body.

    Declaration

    Swift

    var restitution: CGFloat

    Objective-C

    @property(nonatomic) CGFloat restitution

    Discussion

    This property is used to determine how much energy the physics body loses when it bounces off another object. The property must be a value between 0.0 and 1.0. The default value is 0.2.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A property that reduces the body’s linear velocity.

    Declaration

    Swift

    var linearDamping: CGFloat

    Objective-C

    @property(nonatomic, assign) CGFloat linearDamping

    Discussion

    This property is used to simulate fluid or air friction forces on the body. The property must be a value between 0.0 and 1.0. The default value is 0.1. If the value is 0.0, no linear damping is applied to the object.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A property that reduces the body’s rotational velocity.

    Declaration

    Swift

    var angularDamping: CGFloat

    Objective-C

    @property(nonatomic, assign) CGFloat angularDamping

    Discussion

    This property is used to simulate fluid or air friction forces on the body. The property must be a value between 0.0 and 1.0. The default value is 0.1. If the value is 0.0, no angular damping is applied to the object.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A mask that defines which categories this physics body belongs to.

    Declaration

    Swift

    var categoryBitMask: UInt32

    Objective-C

    @property(nonatomic, assign) uint32_t categoryBitMask

    Discussion

    Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.

    The default value is 0xFFFFFFFF (all bits set).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A mask that defines which categories of physics bodies can collide with this physics body.

    Declaration

    Swift

    var collisionBitMask: UInt32

    Objective-C

    @property(nonatomic, assign) uint32_t collisionBitMask

    Discussion

    When two physics bodies contact each other, a collision may occur. This body’s collision mask is compared to the other body’s category mask by performing a logical AND operation. If the result is a nonzero value, this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body’s velocity.

    The default value is 0xFFFFFFFF (all bits set).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    categoryBitMask

  • A Boolean value that determines whether the physics world uses a more precise collision detection algorithm.

    Declaration

    Swift

    var usesPreciseCollisionDetection: Bool

    Objective-C

    @property(nonatomic) BOOL usesPreciseCollisionDetection

    Discussion

    The default value is NOfalse. If two bodies in a collision do not perform precise collision detection, and one passes completely through the other in a single frame, no collision is detected. If this property is set to YEStrue on either body, the simulation performs a more precise and more expensive calculation to detect these collisions. This property should be set to YEStrue on small, fast moving bodies.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A mask that defines which categories of bodies cause intersection notifications with this physics body.

    Declaration

    Swift

    var contactTestBitMask: UInt32

    Objective-C

    @property(nonatomic, assign) uint32_t contactTestBitMask

    Discussion

    When two bodies share the same space, each body’s category mask is tested against the other body’s contact mask by performing a logical AND operation. If either comparison results in a nonzero value, an SKPhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in.

    The default value is 0x00000000 (all bits cleared).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    categoryBitMask

  • The physics bodies that this physics body is in contact with.

    Declaration

    Swift

    func allContactedBodies() -> [AnyObject]

    Objective-C

    - (NSArray *)allContactedBodies

    Return Value

    An array of SKPhysicsBody objects that this body is in contact with.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Applies a force to the center of gravity of a physics body.

    Declaration

    Swift

    func applyForce(_ force: CGVector)

    Objective-C

    - (void)applyForce:(CGVector)force

    Parameters

    force

    A vector that describes how much force was applied in each dimension. The force is measured in Newtons.

    Discussion

    This method accelerates the body without imparting any angular acceleration to it. The acceleration is applied for a single simulation step (one frame).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Applies a torque to an object.

    Declaration

    Swift

    func applyTorque(_ torque: CGFloat)

    Objective-C

    - (void)applyTorque:(CGFloat)torque

    Parameters

    torque

    The amount of torque, in Newton-meters.

    Discussion

    This method generates an angular acceleration on the body without causing any linear acceleration. The force is applied for a single simulation step (one frame).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Applies a force to a specific point of a physics body.

    Declaration

    Swift

    func applyForce(_ force: CGVector, atPoint point: CGPoint)

    Objective-C

    - (void)applyForce:(CGVector)force atPoint:(CGPoint)point

    Parameters

    force

    A vector that describes how much force was applied in each dimension. The force is measured in Newtons.

    point

    A point in scene coordinates that defines where the force was applied to the physics body.

    Discussion

    Because the force is applied to a specific point on the body, it may impart both linear acceleration and angular acceleration. The force is applied for a single simulation step (one frame).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Applies an impulse to the center of gravity of a physics body.

    Declaration

    Swift

    func applyImpulse(_ impulse: CGVector)

    Objective-C

    - (void)applyImpulse:(CGVector)impulse

    Parameters

    impulse

    A vector that describes how much momentum was imparted in each dimension. The impulse is measured in Newton-seconds.

    Discussion

    This method affects the body’s linear velocity without changing the body’s angular velocity.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Applies an impulse that imparts angular momentum to an object.

    Declaration

    Swift

    func applyAngularImpulse(_ impulse: CGFloat)

    Objective-C

    - (void)applyAngularImpulse:(CGFloat)impulse

    Parameters

    impulse

    The magnitude of the impulse. The impulse is measured in Newton-seconds.

    Discussion

    This method affects the body’s angular velocity without changing the body’s linear velocity.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Applies an impulse to a specific point of a physics body.

    Declaration

    Swift

    func applyImpulse(_ impulse: CGVector, atPoint point: CGPoint)

    Objective-C

    - (void)applyImpulse:(CGVector)impulse atPoint:(CGPoint)point

    Parameters

    impulse

    A vector that describes how much momentum to impart to the body. The impulse is measured in Newton-seconds.

    point

    A point in scene coordinates that defines where the impulse was applied to the physics body.

    Discussion

    Because this impulse is applied to a specific point on the object, it may change both the body’s velocity and angular velocity.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • velocity velocity Property

    The physics body’s velocity vector, measured in meters per second.

    Declaration

    Swift

    var velocity: CGVector

    Objective-C

    @property(nonatomic) CGVector velocity

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • The physics body’s angular speed.

    Declaration

    Swift

    var angularVelocity: CGFloat

    Objective-C

    @property(nonatomic) CGFloat angularVelocity

    Discussion

    The angular velocity is a pseudo vector around an axis vector of (0.0,0.0,1.0) measured in radians per second.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • resting resting Property

    A Boolean property that indicates whether the object is at rest within the physics simulation.

    Declaration

    Swift

    var resting: Bool

    Objective-C

    @property(nonatomic, getter=isResting) BOOL resting

    Discussion

    This property is automatically set to YEStrue by the physics simulation when it determines that the body is at rest. This means that the body is at rest on another body in the system. Resting bodies do not participate in the physics simulation until an impulse is applied to the object or another object collides with it. This improves the performance of the physics simulation. If all bodies in the world are resting, the entire simulation is at rest, reducing the number of calculations that are performed by the physics world.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • node node Property

    The node that this body is connected to. (read-only)

    Declaration

    Swift

    weak var node: SKNode? { get }

    Objective-C

    @property(nonatomic, readonly, weak) SKNode *node

    Discussion

    You associate the body with a node by assigning it to the physicsBody property of the SKNode object. If the body is not associated with a node, the value is nil.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • joints joints Property

    The joints connected to this physics body. (read-only)

    Declaration

    Swift

    var joints: [AnyObject] { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *joints

    Discussion

    This property holds an array of SKPhysicsJoint objects that define all joints added to the scene’s physics world that are connected to this physics body.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • A mask that defines which categories of physics fields can exert forces on this physics body.

    Declaration

    Swift

    var fieldBitMask: UInt32

    Objective-C

    @property(nonatomic, assign) uint32_t fieldBitMask

    Discussion

    When a physics body is inside the region of an SKFieldNode object, that field node’s categoryBitMask property is compared to this physics body’s fieldBitMask property by performing a logical AND operation. If the result is a nonzero value, the field node’s effect is applied to the physics body.

    The default value is 0xFFFFFFFF (all bits set).

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • charge charge Property

    The electrical charge of the physics body.

    Declaration

    Swift

    var charge: CGFloat

    Objective-C

    @property(nonatomic) CGFloat charge

    Discussion

    The electrical charge is used by electromagnetic fields to calculate electromagnetic force effects on the physics body. See SKFieldNode Class Reference.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.

  • pinned pinned Property

    A Boolean value that indicates whether the physics body’s node is pinned to its parent node.

    Declaration

    Swift

    var pinned: Bool

    Objective-C

    @property(nonatomic) BOOL pinned

    Discussion

    The default value is NOfalse. If YEStrue, the node’s position is fixed relative to its parent. The node’s position cannot be changed by actions or physics forces. The node can freely rotate around its position in response to collisions or other forces. If the parent node has a physics body, the two physics bodies are treated as if they are connected with a pin joint.

    Import Statement

    Objective-C

    @import SpriteKit;

    Swift

    import SpriteKit

    Availability

    Available in iOS 8.0 and later.