Class

SKPhysicsWorld

An object which encapsulates a scene's physics simulation.

Overview

An SKPhysicsWorld object simulates collisions and other physical properties. You do not create SKPhysicsWorld objects directly; instead, read the physicsWorld property of an SKScene object.The physics world object allows you to perform the following tasks:

  • Set global properties for the simulation, such as gravity

  • Create joints between two physics bodies in the scene

  • Set a delegate to receive notifications when two physics bodies are in contact with each other

  • Determine which physics bodies within the scene intersect with points, rectangles, or rays

Symbols

Configuring the Physics World Simulation

var gravity: CGVector

A vector that specifies the gravitational acceleration applied to physics bodies in the physics world.

var speed: CGFloat

The rate at which the simulation executes.

Joining Physics Bodies Together

func add(SKPhysicsJoint)

Adds a joint to the physics world.

func removeAllJoints()

Removes all joints from the physics world.

func remove(SKPhysicsJoint)

Removes a specific joint from the physics world.

Detecting Collisions in the Physics World

var contactDelegate: SKPhysicsContactDelegate?

A delegate that is called when two physics bodies come in contact with each other.

Searching for Bodies in the World

func body(alongRayStart: CGPoint, end: CGPoint)

Searches for the first physics body that intersects a ray.

func body(at: CGPoint)

Searches for the first physics body that contains a point.

func body(in: CGRect)

Searches for the first physics body that intersects the specified rectangle.

func enumerateBodies(at: CGPoint, using: (SKPhysicsBody, UnsafeMutablePointer<ObjCBool>) -> Void)

Enumerates all the physics bodies in the scene that contain a point.

func enumerateBodies(in: CGRect, using: (SKPhysicsBody, UnsafeMutablePointer<ObjCBool>) -> Void)

Enumerates all the physics bodies in the scene that intersect the specified rectangle.

Working with Physics Fields

func sampleFields(at: vector_float3)

Samples all of the field nodes in the scene and returns the summation of their forces at that point.

Relationships

Inherits From