Edit

Share via


SKPhysicsJointLimit.Create Method

Definition

Factory method for creating a rope-like connection between two physics body.

[Foundation.Export("jointWithBodyA:bodyB:anchorA:anchorB:")]
public static SpriteKit.SKPhysicsJointLimit Create (SpriteKit.SKPhysicsBody bodyA, SpriteKit.SKPhysicsBody bodyB, CoreGraphics.CGPoint anchorA, CoreGraphics.CGPoint anchorB);
static member Create : SpriteKit.SKPhysicsBody * SpriteKit.SKPhysicsBody * CoreGraphics.CGPoint * CoreGraphics.CGPoint -> SpriteKit.SKPhysicsJointLimit

Parameters

anchorA
CGPoint
anchorB
CGPoint

Returns

Attributes

Remarks

The SKNodes associated with bodyA and bodyB must be added to the SKScene prior to calling this method or Sprite Kit will crash. The following example demonstrates the proper order:

var node1 = CreateNodeSomehow();
var node2 = CreateNodeSomehow();
//var joint = SKPhysicsJointLimit.Create(node1.PhysicsBody, node2.PhysicsBody, node1.Position, node2.Position); //NO. This will crash.
mySkScene.AddChild(node1);
mkSkScene.AddChild(node2);
var joint SKPhysicsJointLimit.Create(node1.PhysicsBody, node2.PhysicsBody, node1.Position, node2.Position); //YES. Works fine.
mySkScene.PhysicsWorld.AddJoint(joint);            

(Other types of SKPhysicsJoint can be created prior to the nodes being added to the scene-graph, although the nodes must be added to the scene-graph before AddJoint(SKPhysicsJoint) is called.)

Applies to