SKPhysicsBody Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
An object that reacts to the physics simulation of the SKScene's PhysicsWorld.
[Foundation.Register("SKPhysicsBody", true)]
public class SKPhysicsBody : Foundation.NSObject, Foundation.INSCopying, Foundation.INSSecureCoding, IDisposable
[<Foundation.Register("SKPhysicsBody", true)>]
type SKPhysicsBody = class
inherit NSObject
interface INSCoding
interface INativeObject
interface IDisposable
interface INSCopying
interface INSSecureCoding
- Inheritance
- Attributes
- Implements
Remarks
The visual appearance of a SKScene is determined by its SKNodes. The physics simulation of a SKScene is determined by the SKPhysicsWorld object of the SKScene's PhysicsWorld property. The physics of that word are applied to those SKNodes that have a non-null PhysicsBody.
The following example demonstrates a simple dynamic system:
var blockSize = new CGSize(20, 20);
var node1 = new SKSpriteNode(UIColor.Red, blockSize) {
Position = new CGPoint(100, 100),
Name = "Red",
PhysicsBody = SKPhysicsBody.BodyWithRectangleOfSize(blockSize),
};
var node2 = new SKSpriteNode(UIColor.Green, blockSize) {
Position = new CGPoint(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 SKNodes to the scene-graph prior to setting SKPhysicsJoints or Sprite Kit may segfault.
Constructors
| Name | Description |
|---|---|
| SKPhysicsBody(NativeHandle) |
A constructor used when creating managed representations of unmanaged objects. Called by the runtime. |
| SKPhysicsBody(NSCoder) |
A constructor that initializes the object from the data stored in the unarchiver object. |
| SKPhysicsBody(NSObjectFlag) |
Constructor to call on derived classes to skip initialization and merely allocate the object. |
Properties
| Name | Description |
|---|---|
| AccessibilityAttributedUserInputLabels | (Inherited from NSObject) |
| AccessibilityRespondsToUserInteraction | (Inherited from NSObject) |
| AccessibilityTextualContext | (Inherited from NSObject) |
| AccessibilityUserInputLabels | (Inherited from NSObject) |
| AffectedByGravity | |
| AllContactedBodies | |
| AllowsRotation | |
| AngularDamping | |
| AngularVelocity | |
| Area | |
| CategoryBitMask | |
| Charge | |
| Class | (Inherited from NSObject) |
| ClassHandle |
The Objective-C class handle for this class. |
| CollisionBitMask | |
| ContactTestBitMask | |
| DebugDescription | (Inherited from NSObject) |
| Density | |
| Description | (Inherited from NSObject) |
| Dynamic |
Gets or sets a value the tells whether the physics body is affected by forces and impulses in the simulation. |
| ExposedBindings | (Inherited from NSObject) |
| FieldBitMask | |
| Friction | |
| Handle |
Handle (pointer) to the unmanaged object representation. (Inherited from NSObject) |
| IsDirectBinding | (Inherited from NSObject) |
| IsProxy | (Inherited from NSObject) |
| Joints | |
| LinearDamping | |
| Mass | |
| Node | |
| Pinned | |
| Resting |
Gets or sets a value that tells whether the body is resting on another body in the simulation, and thus does not participate in the simulation. |
| Restitution | |
| RetainCount | (Inherited from NSObject) |
| Self | (Inherited from NSObject) |
| Superclass | (Inherited from NSObject) |
| SuperHandle |
Handle used to represent the methods in the base class for this NSObject. (Inherited from NSObject) |
| UsesPreciseCollisionDetection | |
| Velocity | |
| Zone | (Inherited from NSObject) |