C# Class LitDev.LDPhysics

Afficher le fichier Open project: litdev1/LitDev

Méthodes publiques

Méthode Description
AddChain ( Primitive shape1, Primitive shape2 ) : Primitive

Add a chain between two existing shapes.

AddExplosion ( Primitive posX, Primitive posY, Primitive power, Primitive damping, Primitive colour ) : void

Make an explosion, which consists of 50x20kg particles blast apart over 500ms.

AddFixedAnchor ( Primitive posX, Primitive posY ) : Primitive

Add a new small, transparent shape to be used as a fixed anchor point.

AddFixedShape ( Primitive shapeName, Primitive friction, Primitive restitution ) : void

Add an existing SmallBasic shape to the physics engine as a fixed (non-dynamic) shape with friction and restitution that affects shapes that hit it.

AddInactiveShape ( Primitive shapeName ) : void

Add an existing SmallBasic shape to the physics engine as an inactive (non-dynamic and non-interacting) shape which only moves with the PanView method.

AddMovingAnchor ( Primitive posX, Primitive posY ) : Primitive

Add a new small, transparent and high density shape to be used as a moving anchor point.

AddMovingShape ( Primitive shapeName, Primitive friction, Primitive restitution, Primitive density ) : void

Add an existing SmallBasic shape to the physics engine as a moving (dynamic) shape.

AddRope ( Primitive shape1, Primitive shape2 ) : Primitive

Add a rope between two existing shapes.

AttachShapes ( Primitive shape1, Primitive shape2 ) : void

Connect two shapes to move together as one. The shapes are connected with a distance joint and may wobble a bit if they are hit.

AttachShapesWithJoint ( Primitive shape1, Primitive shape2, Primitive type, Primitive collide, Primitive parameters ) : Primitive

Connect two shapes to move together as one with one of several joint types. These can be advanced and require reference to Box2D manual. In many cases it is best to prevent shape rotation for the joints to behave as desired. Multiple joints may also be applied to shapes. The methods use the initial shape positions, so set these first.

AttachShapesWithRotation ( Primitive shape1, Primitive shape2 ) : void

Connect two shapes to move together as one, but allow the shapes to rotate about each other.

BoxShape ( Primitive shapeName, Primitive x1, Primitive y1, Primitive x2, Primitive y2 ) : void

Set a shape to remain within a box within the view. This is similar to PanView, except that the view pans automatically to keep the specified shape within a box region of the GraphicsWindow. Only one shape can be boxed. To unset shape box, set the shapeName to "".

BrakeTire ( Primitive shapeName ) : void

Apply a brake to a tire shape.

DetachJoint ( Primitive jointName ) : void

Disconnect two shapes that were previously joined with a joint.

DetachShapes ( Primitive shape1, Primitive shape2 ) : void

Disconnect two shapes that were previously attached.

DisconnectShape ( Primitive shapeName ) : void

Disconnect shape from the physics engine without deleting the shape.

DoTimestep ( ) : void

Perform a time-step update.

FollowShapeX ( Primitive shapeName ) : void

Set a shape to remain stationary at X position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual X location. Only one shape can be followed in X direction. To unset shape following, set the shapeName to "".

FollowShapeY ( Primitive shapeName ) : void

Set a shape to remain stationary at Y position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual Y location. Only one shape can be followed in Y direction. To unset shape following, set the shapeName to "".

GetAllShapesAt ( Primitive posX, Primitive posY ) : Primitive

Get an array of all the physics engine shapes (if any) at the input coordinates. The coordinates for this method are the physics engine coordinates if panning is present.

GetAngle ( Primitive shapeName ) : Primitive

Get the angle of rotation for the shape.

GetCollisions ( Primitive shapeName ) : Primitive

Get an array of all the shapes that the specified shape collided with during the last DoTimestep().

GetContacts ( Primitive posX, Primitive posY, Primitive distance ) : Primitive

Get a list of shapes that collided within a distance of a specified contact point.

GetInertia ( Primitive shapeName ) : Primitive

Get the moment of inertia of a shape.

GetMass ( Primitive shapeName ) : Primitive

Get the mass of a shape.

GetPan ( ) : Primitive

Get the current pan offset, see PanView, FollowShapeX(Y) and BoxShape. World coordinates = screen coordinates + pan offset.

GetPosition ( Primitive shapeName ) : Primitive

Get the centre of the shape coordinates.

GetRotation ( Primitive shapeName ) : Primitive

Get the shape rotation speed.

GetShapeAt ( Primitive posX, Primitive posY ) : Primitive

Get the shape (if any) at the input coordinates. The coordinates for this method are the screen coordinates if panning is present.

GetTireInformation ( Primitive shapeName ) : Primitive

Get tire information, it includes: Skid (if this value exceeds the property AntiSkid, then the tire is skidding) Crash (the value is the speed of the impact)

GetTireProperties ( Primitive shapeName ) : Primitive

Get tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores steering more quickly) BrakeStraighten (higher value restores steering more quickly while braking)

GetVelocity ( Primitive shapeName ) : Primitive

Get the velocity of the shape.

GroupShapes ( Primitive shape1, Primitive shape2 ) : void

Solidly group two shapes to move together as one. Shape1 is added to shape2 to act as one shape.

Help ( ) : void

This function is just to display this help. The extension uses Box2D (http://box2d.org) as an engine and provides an interface between it and the graphics capabilities of SmallBasic. Only shapes that are connected to the physics engine take part in the motion physics, for example you may add normal shapes (e.g. a gun and not connect it to the physics engine). Once a shape is connected to the engine, it is best to only interact with it through the methods provided by the extension. All positions are in the SmallBasic GraphicsWindow pixels and refer to shape centres. Image and text shapes are treated as rectangles, and ellipses as circles; there is also triangle and convex polygon support, but not lines. Images may be treated as circles by setting the property LoadImagesAsCircles to "True". One issue that Box2D has difficulty with is small fast moving objects that can 'tunnel' through other shapes without being deflected (see the SetBullet option). Another problem is shapes of very different size and hence mass, especially large shapes when they are connected together. It may be necessary to modify the density for these (the Anchor options are an attempt to automate this a bit), otherwise the default density of 1 is good. Resist the temptation to connect too many shapes together. It may be possible to improve the stability of some 'difficult' models using the TimestepControl settings, but the defaults look good for most cases. Do not call the physics methods inside SmallBasic event subroutines directly, rather set flags that can be processed in a main game loop. There are sample SmallBasic programs and a Getting Started Guide that comes with the extension dll - this is the best place to start. Report bugs and problems to the SmallBasic forum (http://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads), but first simplify your SmallBasic code to isolate the issue before providing a short 'runnable' code sample.

MoveTire ( Primitive shapeName, Primitive force ) : void

Move a tire shape, apply a forward or backward force.

PanView ( Primitive panHorizontal, Primitive panVertical ) : void

Pan the camera view, including window boundaries.

RayCast ( Primitive shapeName, Primitive angle, Primitive distance ) : Primitive

Cast an invisible ray to detect the proximity of shapes.

ReadJson ( Primitive fileName, Primitive scale, Primitive reverseY, Primitive stationary, Primitive offsetX, Primitive offsetY ) : Primitive

Read in a json script compatible with R.U.B.E. and create a LDPhysics model. See https://www.iforce2d.net/rube for more details.

RemoveChain ( Primitive shapeName ) : void

Remove a chain.

RemoveFrozen ( ) : void

Removes all frozen shapes - outside the AABB for the engine.

RemoveRope ( Primitive shapeName ) : void

Remove a rope.

RemoveShape ( Primitive shapeName ) : void

Remove a shape.

Reset ( ) : void

Reset (delete all physics engine attached shapes).

SetAABB ( Primitive minX, Primitive maxX, Primitive minY, Primitive maxY ) : void

The physics engine AABB (axis-aligned bounding box). The units are the engine units of m. A Reset is required after setting. It is not recommended to change this.

SetAngle ( Primitive shapeName, Primitive angle ) : void

Reset the angle of rotation for a shape.

SetBoundaries ( Primitive left, Primitive right, Primitive top, Primitive bottom ) : void

Set solid boundaries (positioning a boundary outside the GraphicsWindow removes it).

SetBullet ( Primitive shapeName ) : void

Set a shape as a bullet. This prevents 'tunnelling' of fast moving small objects at the expense of performance.

SetDamping ( Primitive shapeName, Primitive linear, Primitive angular ) : void

Set a damping factor for a shape (default 0).

SetForce ( Primitive shapeName, Primitive forceX, Primitive forceY ) : void

Set a force to apply to a shape (Remember F = ma).

SetGravity ( Primitive gravX, Primitive gravY ) : void

Set the gravity direction and magnitude (default 0,100).

SetGroup ( Primitive shapeName, Primitive group, Primitive mask ) : void

Control which sprites interact (collide) with other shapes.

SetImpulse ( Primitive shapeName, Primitive impulseX, Primitive impulseY ) : void

Set an impulse to a shape (a kick).

SetJointMotor ( Primitive jointName, Primitive speed, Primitive maxForce ) : void

Set a motor for selected joints (Line, Prismatic_H, Prismatic_V and Revolute).

SetPosition ( Primitive shapeName, Primitive posX, Primitive posY, Primitive angle ) : void

Reset shape position.

SetRotation ( Primitive shapeName, Primitive rotation ) : void

Set shape rotation speed.

SetShapeGravity ( Primitive shapeName, Primitive gravX, Primitive gravY ) : void

Set the gravity direction and magnitude for an individual shape (default 0,100).

SetTire ( Primitive shapeName ) : void

Set an object to act as a drivable tire for a top down game. Usually gravity will be 0 and the shape should already be added to the engine. The object should be initially positioned facing forward up on the display.

SetTireProperties ( Primitive shapeName, Primitive properties ) : void

Set tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores stearing more quickly) BrakeStraighten (higher value restores stearing more quickly while braking)

SetTorque ( Primitive shapeName, Primitive torque ) : void

Set a torque to a shape (a rotational kick).

SetVelocity ( Primitive shapeName, Primitive velX, Primitive velY ) : void

Set the velocity of a shape.

TimestepControl ( Primitive timestep, Primitive velocityIterations, Primitive positionIterations ) : void

Modify default timestep control parameters - also can be set using individual parameters.

ToggleMoving ( Primitive shapeName ) : void

Toggle a moving shape to be fixed and vice-versa. This method also sets the rotation to be on or off to match if it is moving or fixed.

ToggleRotation ( Primitive shapeName ) : void

Toggle a shape to not rotate and vice-versa. This method toggles the rotation property for fixed and moving shapes.

ToggleSensor ( Primitive shapeName ) : void

Toggle a shape to act as a sensor and vice-versa. A sensor shape does not interact with other shapes, but still provides collision data.

TurnTire ( Primitive shapeName, Primitive torque ) : void

Turn a tire shape, steer left or right.

UngroupShapes ( Primitive shape1, Primitive shape2 ) : void

Remove shape group pairing.

UnsetBullet ( Primitive shapeName ) : void

Unset a shape as a bullet. This reverts the shape to normal collision detection.

WakeAll ( ) : void

Wake all sleeping shapes - shapes sleep due to no applied forces or contacts. They wake automatically on any contact or applied force, so this action is rarely required.

WriteJson ( Primitive fileName ) : void

Write out a json script compatible with R.U.B.E. from current LDPhysics model. See https://www.iforce2d.net/rube for more details.

Private Methods

Méthode Description
Cast ( double value, bool reverseY ) : Primitive
GetJointName ( JsonJoint joint ) : string

Method Details

AddChain() public static méthode

Add a chain between two existing shapes.
public static AddChain ( Primitive shape1, Primitive shape2 ) : Primitive
shape1 Primitive /// First shape. ///
shape2 Primitive /// Second shape. ///
Résultat Primitive

AddExplosion() public static méthode

Make an explosion, which consists of 50x20kg particles blast apart over 500ms.
public static AddExplosion ( Primitive posX, Primitive posY, Primitive power, Primitive damping, Primitive colour ) : void
posX Primitive The X coordinate of the explosion.
posY Primitive The Y coordinate of the explosion.
power Primitive The explosion force, this is the initial velocity of the blast particles.
damping Primitive A damping for the blast, the smaller this value the larger the blast range (default 10).
colour Primitive An optional colour of the explosion particles ("" for none).
Résultat void

AddFixedAnchor() public static méthode

Add a new small, transparent shape to be used as a fixed anchor point.
public static AddFixedAnchor ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate of the anchor. ///
posY Primitive /// The Y coordinate of the anchor. ///
Résultat Primitive

AddFixedShape() public static méthode

Add an existing SmallBasic shape to the physics engine as a fixed (non-dynamic) shape with friction and restitution that affects shapes that hit it.
public static AddFixedShape ( Primitive shapeName, Primitive friction, Primitive restitution ) : void
shapeName Primitive /// The name of the shape. ///
friction Primitive /// The shape friction (usually 0 to 1). ///
restitution Primitive /// The shape restitution or bounciness (usually 0 to 1). ///
Résultat void

AddInactiveShape() public static méthode

Add an existing SmallBasic shape to the physics engine as an inactive (non-dynamic and non-interacting) shape which only moves with the PanView method.
public static AddInactiveShape ( Primitive shapeName ) : void
shapeName Primitive /// The name of the shape. ///
Résultat void

AddMovingAnchor() public static méthode

Add a new small, transparent and high density shape to be used as a moving anchor point.
public static AddMovingAnchor ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate of the anchor. ///
posY Primitive /// The Y coordinate of the anchor. ///
Résultat Primitive

AddMovingShape() public static méthode

Add an existing SmallBasic shape to the physics engine as a moving (dynamic) shape.
public static AddMovingShape ( Primitive shapeName, Primitive friction, Primitive restitution, Primitive density ) : void
shapeName Primitive /// The name of the shape. ///
friction Primitive /// The shape friction (usually 0 to 1). ///
restitution Primitive /// The shape restitution or bounciness (usually 0 to 1). /// If a negative value is set for restitution, then the shape will be added with a very small size which may be used to add an inactive image that can be grouped within an irregular compound shape that matches the image boundary. ///
density Primitive /// The shape density (default 1). ///
Résultat void

AddRope() public static méthode

Add a rope between two existing shapes.
public static AddRope ( Primitive shape1, Primitive shape2 ) : Primitive
shape1 Primitive /// First shape. ///
shape2 Primitive /// Second shape. ///
Résultat Primitive

AttachShapes() public static méthode

Connect two shapes to move together as one. The shapes are connected with a distance joint and may wobble a bit if they are hit.
public static AttachShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
Résultat void

AttachShapesWithJoint() public static méthode

Connect two shapes to move together as one with one of several joint types. These can be advanced and require reference to Box2D manual. In many cases it is best to prevent shape rotation for the joints to behave as desired. Multiple joints may also be applied to shapes. The methods use the initial shape positions, so set these first.
public static AttachShapesWithJoint ( Primitive shape1, Primitive shape2, Primitive type, Primitive collide, Primitive parameters ) : Primitive
shape1 Primitive The first shape name.
shape2 Primitive The second shape name.
type Primitive One of the following joint types. /// /// "Distance" - maintain a fixed distance between the shapes. /// "Gear" - link Prismatic or Revolute joints (previously created) of 2 shapes. /// "Line" - move the shapes along a line initially connecting the shapes. /// "Mouse" - move the shape to follow the mouse (both shape names should be the same). /// "Prismatic_H" - move shapes vertically along a line between the two shapes. /// "Prismatic_V" - move shapes horizontally along a line between the two shapes. /// "Pulley" - a pulley system, one shape moves up as the other moves down - position the shapes initially at the extreme points of the pulley motion. /// "Revolute" - the shapes can rotate about each other. ///
collide Primitive The connected shapes can interact with each other "True" or "False" (default). ///
parameters Primitive Optional parameters (default ""), multiple parameters are in an array. /// /// "Distance" - damping ratio (default 0) /// "Gear" - gear ratio, first joint, second joint (default 1, auto detect joints) /// "Line" - X direction, Y direction, lower translation, upper translation (default line connecting shapes, no limits) /// "Mouse" - max acceleration, damping ratio (default 10000, 0.7) /// "Prismatic_H" - X direction, Y direction, lower translation, upper translation (default 1,0, no limits) /// "Prismatic_V" - X direction, Y direction, lower translation, upper translation (default 0,1, no limits) /// "Pulley" - pulley ratio (block and tackle) (default 1) /// "Revolute" - lower angle, upper angle (default no limits) ///
Résultat Primitive

AttachShapesWithRotation() public static méthode

Connect two shapes to move together as one, but allow the shapes to rotate about each other.
public static AttachShapesWithRotation ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
Résultat void

BoxShape() public static méthode

Set a shape to remain within a box within the view. This is similar to PanView, except that the view pans automatically to keep the specified shape within a box region of the GraphicsWindow. Only one shape can be boxed. To unset shape box, set the shapeName to "".
public static BoxShape ( Primitive shapeName, Primitive x1, Primitive y1, Primitive x2, Primitive y2 ) : void
shapeName Primitive The shape to box or "".
x1 Primitive The left x coordinate of the box.
y1 Primitive The top y coordinate of the box.
x2 Primitive The right x coordinate of the box.
y2 Primitive The bottom y coordinate of the box.
Résultat void

BrakeTire() public static méthode

Apply a brake to a tire shape.
public static BrakeTire ( Primitive shapeName ) : void
shapeName Primitive The tire shape to brake.
Résultat void

DetachJoint() public static méthode

Disconnect two shapes that were previously joined with a joint.
public static DetachJoint ( Primitive jointName ) : void
jointName Primitive /// The joint name. ///
Résultat void

DetachShapes() public static méthode

Disconnect two shapes that were previously attached.
public static DetachShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
Résultat void

DisconnectShape() public static méthode

Disconnect shape from the physics engine without deleting the shape.
public static DisconnectShape ( Primitive shapeName ) : void
shapeName Primitive /// The shape name. ///
Résultat void

DoTimestep() public static méthode

Perform a time-step update.
public static DoTimestep ( ) : void
Résultat void

FollowShapeX() public static méthode

Set a shape to remain stationary at X position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual X location. Only one shape can be followed in X direction. To unset shape following, set the shapeName to "".
public static FollowShapeX ( Primitive shapeName ) : void
shapeName Primitive /// The shape to follow or "". ///
Résultat void

FollowShapeY() public static méthode

Set a shape to remain stationary at Y position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual Y location. Only one shape can be followed in Y direction. To unset shape following, set the shapeName to "".
public static FollowShapeY ( Primitive shapeName ) : void
shapeName Primitive /// The shape to follow or "". ///
Résultat void

GetAllShapesAt() public static méthode

Get an array of all the physics engine shapes (if any) at the input coordinates. The coordinates for this method are the physics engine coordinates if panning is present.
public static GetAllShapesAt ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate. ///
posY Primitive /// The Y coordinate. ///
Résultat Primitive

GetAngle() public static méthode

Get the angle of rotation for the shape.
public static GetAngle ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
Résultat Primitive

GetCollisions() public static méthode

Get an array of all the shapes that the specified shape collided with during the last DoTimestep().
public static GetCollisions ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape to check for collisions. ///
Résultat Primitive

GetContacts() public static méthode

Get a list of shapes that collided within a distance of a specified contact point.
public static GetContacts ( Primitive posX, Primitive posY, Primitive distance ) : Primitive
posX Primitive /// The X coordinate of a contact position to check. ///
posY Primitive /// The Y coordinate of a contact position to check. ///
distance Primitive /// A maximum distance from the contact point for the contact. ///
Résultat Primitive

GetInertia() public static méthode

Get the moment of inertia of a shape.
public static GetInertia ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
Résultat Primitive

GetMass() public static méthode

Get the mass of a shape.
public static GetMass ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
Résultat Primitive

GetPan() public static méthode

Get the current pan offset, see PanView, FollowShapeX(Y) and BoxShape. World coordinates = screen coordinates + pan offset.
public static GetPan ( ) : Primitive
Résultat Primitive

GetPosition() public static méthode

Get the centre of the shape coordinates.
public static GetPosition ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
Résultat Primitive

GetRotation() public static méthode

Get the shape rotation speed.
public static GetRotation ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
Résultat Primitive

GetShapeAt() public static méthode

Get the shape (if any) at the input coordinates. The coordinates for this method are the screen coordinates if panning is present.
public static GetShapeAt ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate. ///
posY Primitive /// The Y coordinate. ///
Résultat Primitive

GetTireInformation() public static méthode

Get tire information, it includes: Skid (if this value exceeds the property AntiSkid, then the tire is skidding) Crash (the value is the speed of the impact)
public static GetTireInformation ( Primitive shapeName ) : Primitive
shapeName Primitive The tire shape.
Résultat Primitive

GetTireProperties() public static méthode

Get tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores steering more quickly) BrakeStraighten (higher value restores steering more quickly while braking)
public static GetTireProperties ( Primitive shapeName ) : Primitive
shapeName Primitive The tire shape.
Résultat Primitive

GetVelocity() public static méthode

Get the velocity of the shape.
public static GetVelocity ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
Résultat Primitive

GroupShapes() public static méthode

Solidly group two shapes to move together as one. Shape1 is added to shape2 to act as one shape.
public static GroupShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
Résultat void

Help() public static méthode

This function is just to display this help. The extension uses Box2D (http://box2d.org) as an engine and provides an interface between it and the graphics capabilities of SmallBasic. Only shapes that are connected to the physics engine take part in the motion physics, for example you may add normal shapes (e.g. a gun and not connect it to the physics engine). Once a shape is connected to the engine, it is best to only interact with it through the methods provided by the extension. All positions are in the SmallBasic GraphicsWindow pixels and refer to shape centres. Image and text shapes are treated as rectangles, and ellipses as circles; there is also triangle and convex polygon support, but not lines. Images may be treated as circles by setting the property LoadImagesAsCircles to "True". One issue that Box2D has difficulty with is small fast moving objects that can 'tunnel' through other shapes without being deflected (see the SetBullet option). Another problem is shapes of very different size and hence mass, especially large shapes when they are connected together. It may be necessary to modify the density for these (the Anchor options are an attempt to automate this a bit), otherwise the default density of 1 is good. Resist the temptation to connect too many shapes together. It may be possible to improve the stability of some 'difficult' models using the TimestepControl settings, but the defaults look good for most cases. Do not call the physics methods inside SmallBasic event subroutines directly, rather set flags that can be processed in a main game loop. There are sample SmallBasic programs and a Getting Started Guide that comes with the extension dll - this is the best place to start. Report bugs and problems to the SmallBasic forum (http://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads), but first simplify your SmallBasic code to isolate the issue before providing a short 'runnable' code sample.
public static Help ( ) : void
Résultat void

MoveTire() public static méthode

Move a tire shape, apply a forward or backward force.
public static MoveTire ( Primitive shapeName, Primitive force ) : void
shapeName Primitive The tire shape to move.
force Primitive The force to apply, positive is forward, negative is backward.
Résultat void

PanView() public static méthode

Pan the camera view, including window boundaries.
public static PanView ( Primitive panHorizontal, Primitive panVertical ) : void
panHorizontal Primitive /// Pan in the horizontal direction (negative is left). ///
panVertical Primitive /// Pan in the vertical direction (negative is up). ///
Résultat void

RayCast() public static méthode

Cast an invisible ray to detect the proximity of shapes.
public static RayCast ( Primitive shapeName, Primitive angle, Primitive distance ) : Primitive
shapeName Primitive The shape to cast the ray from.
angle Primitive The angle in degrees to check, this can also be an array of angles.
distance Primitive A maximum distance to check.
Résultat Primitive

ReadJson() public static méthode

Read in a json script compatible with R.U.B.E. and create a LDPhysics model. See https://www.iforce2d.net/rube for more details.
public static ReadJson ( Primitive fileName, Primitive scale, Primitive reverseY, Primitive stationary, Primitive offsetX, Primitive offsetY ) : Primitive
fileName Primitive The full path to the json file to read.
scale Primitive Scale all shapes, default 1 (no scaling).
reverseY Primitive Reverse the Y direction up to down ("True" or "False").
stationary Primitive Set all shapes to be initially at rest, joint motors are still enabled ("True" or "False").
offsetX Primitive Add an x coordinate offset to all shapes.
offsetY Primitive Add a y coordinate offset to all shapes, especially useful when reverseY is set.
Résultat Primitive

RemoveChain() public static méthode

Remove a chain.
public static RemoveChain ( Primitive shapeName ) : void
shapeName Primitive /// The chain name. ///
Résultat void

RemoveFrozen() public static méthode

Removes all frozen shapes - outside the AABB for the engine.
public static RemoveFrozen ( ) : void
Résultat void

RemoveRope() public static méthode

Remove a rope.
public static RemoveRope ( Primitive shapeName ) : void
shapeName Primitive /// The rope name. ///
Résultat void

RemoveShape() public static méthode

Remove a shape.
public static RemoveShape ( Primitive shapeName ) : void
shapeName Primitive /// The name of the shape. ///
Résultat void

Reset() public static méthode

Reset (delete all physics engine attached shapes).
public static Reset ( ) : void
Résultat void

SetAABB() public static méthode

The physics engine AABB (axis-aligned bounding box). The units are the engine units of m. A Reset is required after setting. It is not recommended to change this.
public static SetAABB ( Primitive minX, Primitive maxX, Primitive minY, Primitive maxY ) : void
minX Primitive /// The left coordinate of the universe (default -100). ///
maxX Primitive /// The right coordinate of the universe (default 200). ///
minY Primitive /// The top coordinate of the universe (default -100). ///
maxY Primitive /// The bottom coordinate of the universe (default 200). ///
Résultat void

SetAngle() public static méthode

Reset the angle of rotation for a shape.
public static SetAngle ( Primitive shapeName, Primitive angle ) : void
shapeName Primitive /// The shape name. ///
angle Primitive /// The angle of rotation in degrees. ///
Résultat void

SetBoundaries() public static méthode

Set solid boundaries (positioning a boundary outside the GraphicsWindow removes it).
public static SetBoundaries ( Primitive left, Primitive right, Primitive top, Primitive bottom ) : void
left Primitive /// The left boundary X value. ///
right Primitive /// The right boundary X value. ///
top Primitive /// The top boundary Y value. ///
bottom Primitive /// The bottom (ground) boundary Y value. ///
Résultat void

SetBullet() public static méthode

Set a shape as a bullet. This prevents 'tunnelling' of fast moving small objects at the expense of performance.
public static SetBullet ( Primitive shapeName ) : void
shapeName Primitive /// The shape name. ///
Résultat void

SetDamping() public static méthode

Set a damping factor for a shape (default 0).
public static SetDamping ( Primitive shapeName, Primitive linear, Primitive angular ) : void
shapeName Primitive /// The shape to modify. ///
linear Primitive /// Linear damping factor. ///
angular Primitive /// Angular damping factor. ///
Résultat void

SetForce() public static méthode

Set a force to apply to a shape (Remember F = ma).
public static SetForce ( Primitive shapeName, Primitive forceX, Primitive forceY ) : void
shapeName Primitive /// The shape to modify. ///
forceX Primitive /// X component of the force. ///
forceY Primitive /// Y component of the force. ///
Résultat void

SetGravity() public static méthode

Set the gravity direction and magnitude (default 0,100).
public static SetGravity ( Primitive gravX, Primitive gravY ) : void
gravX Primitive /// The X component of gravity. ///
gravY Primitive /// The Y component of gravity. ///
Résultat void

SetGroup() public static méthode

Control which sprites interact (collide) with other shapes.
public static SetGroup ( Primitive shapeName, Primitive group, Primitive mask ) : void
shapeName Primitive /// The shape to modify. ///
group Primitive /// The group that the current shape belongs to (default 0). This should be an integer between 0 and 15. ///
mask Primitive /// An array of groups that this shape will collide with (default all groups 0,1,2,..,14,15). /// To allow the shape to only interact with groups 0, 1 and 4 would be "1=0;2=1;3=4;". ///
Résultat void

SetImpulse() public static méthode

Set an impulse to a shape (a kick).
public static SetImpulse ( Primitive shapeName, Primitive impulseX, Primitive impulseY ) : void
shapeName Primitive /// The shape to modify. ///
impulseX Primitive /// X component of the impulse. ///
impulseY Primitive /// Y component of the impulse. ///
Résultat void

SetJointMotor() public static méthode

Set a motor for selected joints (Line, Prismatic_H, Prismatic_V and Revolute).
public static SetJointMotor ( Primitive jointName, Primitive speed, Primitive maxForce ) : void
jointName Primitive /// The joint name. ///
speed Primitive The desired motor speed.
maxForce Primitive The maximum motor force (torque for Revolute). /// A zero value turns motor off.
Résultat void

SetPosition() public static méthode

Reset shape position.
public static SetPosition ( Primitive shapeName, Primitive posX, Primitive posY, Primitive angle ) : void
shapeName Primitive /// The shape to modify. ///
posX Primitive /// X component shape centre. ///
posY Primitive /// Y component shape centre. ///
angle Primitive /// The angle of rotation in degrees. ///
Résultat void

SetRotation() public static méthode

Set shape rotation speed.
public static SetRotation ( Primitive shapeName, Primitive rotation ) : void
shapeName Primitive /// The shape to modify. ///
rotation Primitive /// The angular rotation speed degrees/s. ///
Résultat void

SetShapeGravity() public static méthode

Set the gravity direction and magnitude for an individual shape (default 0,100).
public static SetShapeGravity ( Primitive shapeName, Primitive gravX, Primitive gravY ) : void
shapeName Primitive /// The shape to modify. ///
gravX Primitive /// The X component of gravity. ///
gravY Primitive /// The Y component of gravity. ///
Résultat void

SetTire() public static méthode

Set an object to act as a drivable tire for a top down game. Usually gravity will be 0 and the shape should already be added to the engine. The object should be initially positioned facing forward up on the display.
public static SetTire ( Primitive shapeName ) : void
shapeName Primitive The shape to make a tire.
Résultat void

SetTireProperties() public static méthode

Set tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores stearing more quickly) BrakeStraighten (higher value restores stearing more quickly while braking)
public static SetTireProperties ( Primitive shapeName, Primitive properties ) : void
shapeName Primitive The tire shape.
properties Primitive An array of one or more properties to set. /// The index is one of the properties (case sensitive) and the value is the property value.
Résultat void

SetTorque() public static méthode

Set a torque to a shape (a rotational kick).
public static SetTorque ( Primitive shapeName, Primitive torque ) : void
shapeName Primitive /// The shape to modify. ///
torque Primitive /// The torque to apply. ///
Résultat void

SetVelocity() public static méthode

Set the velocity of a shape.
public static SetVelocity ( Primitive shapeName, Primitive velX, Primitive velY ) : void
shapeName Primitive /// The shape to modify. ///
velX Primitive /// X component of the velocity. ///
velY Primitive /// Y component of the velocity. ///
Résultat void

TimestepControl() public static méthode

Modify default timestep control parameters - also can be set using individual parameters.
public static TimestepControl ( Primitive timestep, Primitive velocityIterations, Primitive positionIterations ) : void
timestep Primitive /// Time-step (default 0.025). ///
velocityIterations Primitive /// Velocity iterations (default 6). ///
positionIterations Primitive /// Position iterations (default 2). ///
Résultat void

ToggleMoving() public static méthode

Toggle a moving shape to be fixed and vice-versa. This method also sets the rotation to be on or off to match if it is moving or fixed.
public static ToggleMoving ( Primitive shapeName ) : void
shapeName Primitive The shape name.
Résultat void

ToggleRotation() public static méthode

Toggle a shape to not rotate and vice-versa. This method toggles the rotation property for fixed and moving shapes.
public static ToggleRotation ( Primitive shapeName ) : void
shapeName Primitive The shape name.
Résultat void

ToggleSensor() public static méthode

Toggle a shape to act as a sensor and vice-versa. A sensor shape does not interact with other shapes, but still provides collision data.
public static ToggleSensor ( Primitive shapeName ) : void
shapeName Primitive The shape name.
Résultat void

TurnTire() public static méthode

Turn a tire shape, steer left or right.
public static TurnTire ( Primitive shapeName, Primitive torque ) : void
shapeName Primitive The tire shape to turn.
torque Primitive The torque, rotation force to apply, positive is turn right, negative is turn left.
Résultat void

UngroupShapes() public static méthode

Remove shape group pairing.
public static UngroupShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
Résultat void

UnsetBullet() public static méthode

Unset a shape as a bullet. This reverts the shape to normal collision detection.
public static UnsetBullet ( Primitive shapeName ) : void
shapeName Primitive /// The shape name. ///
Résultat void

WakeAll() public static méthode

Wake all sleeping shapes - shapes sleep due to no applied forces or contacts. They wake automatically on any contact or applied force, so this action is rarely required.
public static WakeAll ( ) : void
Résultat void

WriteJson() public static méthode

Write out a json script compatible with R.U.B.E. from current LDPhysics model. See https://www.iforce2d.net/rube for more details.
public static WriteJson ( Primitive fileName ) : void
fileName Primitive The full path to the json file to create.
Résultat void