SpriteKit.SKPhysicsBody Class
An object that reacts to the physics simulation of the SpriteKit.SKScene's SKScene.PhysicsWorld.

See Also: SKPhysicsBody Members

Syntax

[Foundation.Register("SKPhysicsBody", true)]
[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_7_0)]
[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.Mac_10_0 | ObjCRuntime.Platform.Mac_10_1 | ObjCRuntime.Platform.Mac_10_2 | ObjCRuntime.Platform.Mac_10_3 | ObjCRuntime.Platform.Mac_10_4 | ObjCRuntime.Platform.Mac_10_5 | ObjCRuntime.Platform.Mac_10_6 | ObjCRuntime.Platform.Mac_10_7 | ObjCRuntime.Platform.Mac_10_8 | ObjCRuntime.Platform.Mac_10_9 | ObjCRuntime.Platform.Mac_10_10 | ObjCRuntime.Platform.Mac_Version | ObjCRuntime.Platform.Mac_Arch64 | ObjCRuntime.Platform.Mac_Arch)]
public class SKPhysicsBody : Foundation.NSObject, Foundation.INSCoding, Foundation.INSCopying, IDisposable

Remarks

The visual appearance of a SpriteKit.SKScene is determined by its SpriteKit.SKNodes. The physics simulation of a SpriteKit.SKScene is determined by the SpriteKit.SKPhysicsWorld object of the SpriteKit.SKScene's SKScene.PhysicsWorld property. The physics of that word are applied to those SpriteKit.SKNodes that have a non-null SKNode.PhysicsBody.

The following example demonstrates a simple dynamic system:

C# Example

var blockSize = new SizeF(20, 20);
var node1 = new SKSpriteNode(UIColor.Red, blockSize) {
	Position = new PointF(100, 100),
	Name = "Red",
	PhysicsBody = SKPhysicsBody.BodyWithRectangleOfSize(blockSize),
};
var node2 = new SKSpriteNode(UIColor.Green, blockSize) {
	Position = new PointF(150, 100),
	Name = "Green",
	PhysicsBody = SKPhysicsBody.BodyWithRectangleOfSize(blockSize)
};

//Pin node1 in position and connect node2 to it with a spring
node1.PhysicsBody.Dynamic = false;
var joint = SKPhysicsJointSpring.Create(node1.PhysicsBody, node2.PhysicsBody, node1.Position, node2.Position);

//Add nodes to scene
scene.AddChild(node1);
scene.AddChild(node2);

//Add the joint to the physics world
scene.PhysicsWorld.AddJoint(joint);
          

Application developers must add the SpriteKit.SKNodes to the scene-graph prior to setting SpriteKit.SKPhysicsJoints or Sprite Kit may segfault.

Related content

Requirements

Namespace: SpriteKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0