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

See Also: SKPhysicsBody Members

Syntax

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

Remarks

The visual appearance of a MonoTouch.SpriteKit.SKScene is determined by its MonoTouch.SpriteKit.SKNodes. The physics simulation of a MonoTouch.SpriteKit.SKScene is determined by the MonoTouch.SpriteKit.SKPhysicsWorld object of the MonoTouch.SpriteKit.SKScene's SKScene.PhysicsWorld property. The physics of that word are applied to those MonoTouch.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 MonoTouch.SpriteKit.SKNodes to the scene-graph prior to setting MonoTouch.SpriteKit.SKPhysicsJoints or Sprite Kit may segfault.

Related content

Requirements

Namespace: MonoTouch.SpriteKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0