25 KiB
Planck.js API Doc › Globals › World
Class: World
Hierarchy
- World
Index
Constructors
Methods
- clearForces
- createBody
- createDynamicBody
- createJoint
- createKinematicBody
- destroyBody
- destroyJoint
- getAllowSleeping
- getAutoClearForces
- getBodyCount
- getBodyList
- getContactCount
- getContactList
- getContinuousPhysics
- getGravity
- getJointCount
- getJointList
- getProxyCount
- getSubStepping
- getTreeBalance
- getTreeHeight
- getTreeQuality
- getWarmStarting
- isLocked
- off
- on
- publish
- queryAABB
- rayCast
- setAllowSleeping
- setAutoClearForces
- setContinuousPhysics
- setGravity
- setSubStepping
- setWarmStarting
- shiftOrigin
- step
Constructors
constructor
+ new World(def?: WorldDef | Vec2 | null): World
Defined in src/dynamics/World.ts:121
Parameters:
| Name | Type | Description |
|---|---|---|
def? |
WorldDef | Vec2 | null | World definition or gravity vector. |
Returns: World
Methods
clearForces
▸ clearForces(): void
Defined in src/dynamics/World.ts:366
Manually clear the force buffer on all bodies. By default, forces are cleared automatically after each call to step. The default behavior is modified by calling setAutoClearForces. The purpose of this function is to support sub-stepping. Sub-stepping is often used to maintain a fixed sized time step under a variable frame-rate. When you perform sub-stepping you will disable auto clearing of forces and instead call clearForces after all sub-steps are complete in one pass of your game loop.
Returns: void
createBody
▸ createBody(def?: BodyDef): Body
Defined in src/dynamics/World.ts:500
Create a rigid body given a definition. No reference to the definition is retained.
Warning: This function is locked during callbacks.
Parameters:
| Name | Type |
|---|---|
def? |
BodyDef |
Returns: Body
▸ createBody(position: Vec2, angle?: number): Body
Defined in src/dynamics/World.ts:501
Parameters:
| Name | Type |
|---|---|
position |
Vec2 |
angle? |
number |
Returns: Body
createDynamicBody
▸ createDynamicBody(def?: BodyDef): Body
Defined in src/dynamics/World.ts:522
Parameters:
| Name | Type |
|---|---|
def? |
BodyDef |
Returns: Body
▸ createDynamicBody(position: Vec2, angle?: number): Body
Defined in src/dynamics/World.ts:523
Parameters:
| Name | Type |
|---|---|
position |
Vec2 |
angle? |
number |
Returns: Body
createJoint
▸ createJoint‹T›(joint: T): T | null
Defined in src/dynamics/World.ts:637
Create a joint to constrain bodies together. No reference to the definition is retained. This may cause the connected bodies to cease colliding.
Warning: This function is locked during callbacks.
Type parameters:
▪ T: Joint
Parameters:
| Name | Type |
|---|---|
joint |
T |
Returns: T | null
createKinematicBody
▸ createKinematicBody(def?: BodyDef): Body
Defined in src/dynamics/World.ts:537
Parameters:
| Name | Type |
|---|---|
def? |
BodyDef |
Returns: Body
▸ createKinematicBody(position: Vec2, angle?: number): Body
Defined in src/dynamics/World.ts:538
Parameters:
| Name | Type |
|---|---|
position |
Vec2 |
angle? |
number |
Returns: Body
destroyBody
▸ destroyBody(b: Body): boolean
Defined in src/dynamics/World.ts:560
Destroy a rigid body given a definition. No reference to the definition is retained.
Warning: This automatically deletes all associated shapes and joints.
Warning: This function is locked during callbacks.
Parameters:
| Name | Type |
|---|---|
b |
Body |
Returns: boolean
destroyJoint
▸ destroyJoint(joint: Joint): void
Defined in src/dynamics/World.ts:691
Destroy a joint. This may cause the connected bodies to begin colliding. Warning: This function is locked during callbacks.
Parameters:
| Name | Type |
|---|---|
joint |
Joint |
Returns: void
getAllowSleeping
▸ getAllowSleeping(): boolean
Defined in src/dynamics/World.ts:304
Returns: boolean
getAutoClearForces
▸ getAutoClearForces(): boolean
Defined in src/dynamics/World.ts:351
Get the flag that controls automatic clearing of forces after each time step.
Returns: boolean
getBodyCount
▸ getBodyCount(): number
Defined in src/dynamics/World.ts:252
Returns: number
getBodyList
▸ getBodyList(): Body | null
Defined in src/dynamics/World.ts:224
Get the world body list. With the returned body, use Body.getNext to get the next body in the world list. A null body indicates the end of the list.
Returns: Body | null
the head of the world body list.
getContactCount
▸ getContactCount(): number
Defined in src/dynamics/World.ts:263
Get the number of contacts (each may have 0 or more contact points).
Returns: number
getContactList
▸ getContactList(): Contact | null
Defined in src/dynamics/World.ts:248
Get the world contact list. With the returned contact, use Contact.getNext to get the next contact in the world list. A null contact indicates the end of the list.
Warning: contacts are created and destroyed in the middle of a time step. Use ContactListener to avoid missing contacts.
Returns: Contact | null
the head of the world contact list.
getContinuousPhysics
▸ getContinuousPhysics(): boolean
Defined in src/dynamics/World.ts:326
Returns: boolean
getGravity
▸ getGravity(): Vec2
Defined in src/dynamics/World.ts:277
Get the global gravity vector.
Returns: Vec2
getJointCount
▸ getJointCount(): number
Defined in src/dynamics/World.ts:256
Returns: number
getJointList
▸ getJointList(): Joint | null
Defined in src/dynamics/World.ts:234
Get the world joint list. With the returned joint, use Joint.getNext to get the next joint in the world list. A null joint indicates the end of the list.
Returns: Joint | null
the head of the world joint list.
getProxyCount
▸ getProxyCount(): number
Defined in src/dynamics/World.ts:424
Get the number of broad-phase proxies.
Returns: number
getSubStepping
▸ getSubStepping(): boolean
Defined in src/dynamics/World.ts:337
Returns: boolean
getTreeBalance
▸ getTreeBalance(): number
Defined in src/dynamics/World.ts:438
Get the balance of broad-phase dynamic tree.
Returns: number
getTreeHeight
▸ getTreeHeight(): number
Defined in src/dynamics/World.ts:431
Get the height of broad-phase dynamic tree.
Returns: number
getTreeQuality
▸ getTreeQuality(): number
Defined in src/dynamics/World.ts:446
Get the quality metric of broad-phase dynamic tree. The smaller the better. The minimum is 1.
Returns: number
getWarmStarting
▸ getWarmStarting(): boolean
Defined in src/dynamics/World.ts:315
Returns: boolean
isLocked
▸ isLocked(): boolean
Defined in src/dynamics/World.ts:284
Is the world locked (in the middle of a time step).
Returns: boolean
off
▸ off(name: "begin-contact", listener: function): World
Defined in src/dynamics/World.ts:1073
Remove an event listener.
Parameters:
▪ name: "begin-contact"
▪ listener: function
▸ (contact: Contact): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
Returns: World
▸ off(name: "end-contact", listener: function): World
Defined in src/dynamics/World.ts:1074
Remove an event listener.
Parameters:
▪ name: "end-contact"
▪ listener: function
▸ (contact: Contact): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
Returns: World
▸ off(name: "pre-solve", listener: function): World
Defined in src/dynamics/World.ts:1075
Remove an event listener.
Parameters:
▪ name: "pre-solve"
▪ listener: function
▸ (contact: Contact, oldManifold: Manifold): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
oldManifold |
Manifold |
Returns: World
▸ off(name: "post-solve", listener: function): World
Defined in src/dynamics/World.ts:1076
Remove an event listener.
Parameters:
▪ name: "post-solve"
▪ listener: function
▸ (contact: Contact, impulse: ContactImpulse): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
impulse |
ContactImpulse |
Returns: World
▸ off(name: "remove-body", listener: function): World
Defined in src/dynamics/World.ts:1077
Remove an event listener.
Parameters:
▪ name: "remove-body"
▪ listener: function
▸ (body: Body): void
Parameters:
| Name | Type |
|---|---|
body |
Body |
Returns: World
▸ off(name: "remove-joint", listener: function): World
Defined in src/dynamics/World.ts:1078
Remove an event listener.
Parameters:
▪ name: "remove-joint"
▪ listener: function
▸ (joint: Joint): void
Parameters:
| Name | Type |
|---|---|
joint |
Joint |
Returns: World
▸ off(name: "remove-fixture", listener: function): World
Defined in src/dynamics/World.ts:1079
Remove an event listener.
Parameters:
▪ name: "remove-fixture"
▪ listener: function
▸ (fixture: Fixture): void
Parameters:
| Name | Type |
|---|---|
fixture |
Fixture |
Returns: World
on
▸ on(name: "begin-contact", listener: function): World
Defined in src/dynamics/World.ts:1011
Called when two fixtures begin to touch.
Implement contact callbacks to get contact information. You can use these results for things like sounds and game logic. You can also get contact results by traversing the contact lists after the time step. However, you might miss some contacts because continuous physics leads to sub-stepping. Additionally you may receive multiple callbacks for the same contact in a single time step. You should strive to make your callbacks efficient because there may be many callbacks per time step.
Warning: You cannot create/destroy world entities inside these callbacks.
Parameters:
▪ name: "begin-contact"
▪ listener: function
▸ (contact: Contact): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
Returns: World
▸ on(name: "end-contact", listener: function): World
Defined in src/dynamics/World.ts:1025
Called when two fixtures cease to touch.
Implement contact callbacks to get contact information. You can use these results for things like sounds and game logic. You can also get contact results by traversing the contact lists after the time step. However, you might miss some contacts because continuous physics leads to sub-stepping. Additionally you may receive multiple callbacks for the same contact in a single time step. You should strive to make your callbacks efficient because there may be many callbacks per time step.
Warning: You cannot create/destroy world entities inside these callbacks.
Parameters:
▪ name: "end-contact"
▪ listener: function
▸ (contact: Contact): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
Returns: World
▸ on(name: "pre-solve", listener: function): World
Defined in src/dynamics/World.ts:1038
This is called after a contact is updated. This allows you to inspect a contact before it goes to the solver. If you are careful, you can modify the contact manifold (e.g. disable contact). A copy of the old manifold is provided so that you can detect changes. Note: this is called only for awake bodies. Note: this is called even when the number of contact points is zero. Note: this is not called for sensors. Note: if you set the number of contact points to zero, you will not get an endContact callback. However, you may get a beginContact callback the next step.
Warning: You cannot create/destroy world entities inside these callbacks.
Parameters:
▪ name: "pre-solve"
▪ listener: function
▸ (contact: Contact, oldManifold: Manifold): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
oldManifold |
Manifold |
Returns: World
▸ on(name: "post-solve", listener: function): World
Defined in src/dynamics/World.ts:1048
This lets you inspect a contact after the solver is finished. This is useful for inspecting impulses. Note: the contact manifold does not include time of impact impulses, which can be arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly in a separate data structure. Note: this is only called for contacts that are touching, solid, and awake.
Warning: You cannot create/destroy world entities inside these callbacks.
Parameters:
▪ name: "post-solve"
▪ listener: function
▸ (contact: Contact, impulse: ContactImpulse): void
Parameters:
| Name | Type |
|---|---|
contact |
Contact |
impulse |
ContactImpulse |
Returns: World
▸ on(name: "remove-body", listener: function): World
Defined in src/dynamics/World.ts:1050
Listener is called whenever a body is removed.
Parameters:
▪ name: "remove-body"
▪ listener: function
▸ (body: Body): void
Parameters:
| Name | Type |
|---|---|
body |
Body |
Returns: World
▸ on(name: "remove-joint", listener: function): World
Defined in src/dynamics/World.ts:1052
Listener is called whenever a joint is removed implicitly or explicitly.
Parameters:
▪ name: "remove-joint"
▪ listener: function
▸ (joint: Joint): void
Parameters:
| Name | Type |
|---|---|
joint |
Joint |
Returns: World
▸ on(name: "remove-fixture", listener: function): World
Defined in src/dynamics/World.ts:1054
Listener is called whenever a fixture is removed implicitly or explicitly.
Parameters:
▪ name: "remove-fixture"
▪ listener: function
▸ (fixture: Fixture): void
Parameters:
| Name | Type |
|---|---|
fixture |
Fixture |
Returns: World
publish
▸ publish(name: string, arg1?: any, arg2?: any, arg3?: any): number
Defined in src/dynamics/World.ts:1099
Parameters:
| Name | Type |
|---|---|
name |
string |
arg1? |
any |
arg2? |
any |
arg3? |
any |
Returns: number
queryAABB
▸ queryAABB(aabb: AABB, callback: WorldAABBQueryCallback): void
Defined in src/dynamics/World.ts:379
Query the world for all fixtures that potentially overlap the provided AABB.
Parameters:
| Name | Type | Description |
|---|---|---|
aabb |
AABB | The query box. |
callback |
WorldAABBQueryCallback | Called for each fixture found in the query AABB. It may return false to terminate the query. |
Returns: void
rayCast
▸ rayCast(point1: Vec2, point2: Vec2, callback: WorldRayCastCallback): void
Defined in src/dynamics/World.ts:397
Ray-cast the world for all fixtures in the path of the ray. Your callback controls whether you get the closest point, any point, or n-points. The ray-cast ignores shapes that contain the starting point.
Parameters:
| Name | Type | Description |
|---|---|---|
point1 |
Vec2 | The ray starting point |
point2 |
Vec2 | The ray ending point |
callback |
WorldRayCastCallback | A user implemented callback function. |
Returns: void
setAllowSleeping
▸ setAllowSleeping(flag: boolean): void
Defined in src/dynamics/World.ts:291
Enable/disable sleep.
Parameters:
| Name | Type |
|---|---|
flag |
boolean |
Returns: void
setAutoClearForces
▸ setAutoClearForces(flag: boolean): void
Defined in src/dynamics/World.ts:344
Set flag to control automatic clearing of forces after each time step.
Parameters:
| Name | Type |
|---|---|
flag |
boolean |
Returns: void
setContinuousPhysics
▸ setContinuousPhysics(flag: boolean): void
Defined in src/dynamics/World.ts:322
Enable/disable continuous physics. For testing.
Parameters:
| Name | Type |
|---|---|
flag |
boolean |
Returns: void
setGravity
▸ setGravity(gravity: Vec2): void
Defined in src/dynamics/World.ts:270
Change the global gravity vector.
Parameters:
| Name | Type |
|---|---|
gravity |
Vec2 |
Returns: void
setSubStepping
▸ setSubStepping(flag: boolean): void
Defined in src/dynamics/World.ts:333
Enable/disable single stepped continuous physics. For testing.
Parameters:
| Name | Type |
|---|---|
flag |
boolean |
Returns: void
setWarmStarting
▸ setWarmStarting(flag: boolean): void
Defined in src/dynamics/World.ts:311
Enable/disable warm starting. For testing.
Parameters:
| Name | Type |
|---|---|
flag |
boolean |
Returns: void
shiftOrigin
▸ shiftOrigin(newOrigin: Vec2): void
Defined in src/dynamics/World.ts:456
Shift the world origin. Useful for large worlds. The body shift formula is: position -= newOrigin
Parameters:
| Name | Type | Description |
|---|---|---|
newOrigin |
Vec2 | The new origin with respect to the old origin |
Returns: void
step
▸ step(timeStep: number, velocityIterations?: number, positionIterations?: number): void
Defined in src/dynamics/World.ts:781
Take a time step. This performs collision detection, integration, and constraint solution.
Broad-phase, narrow-phase, solve and solve time of impacts.
Parameters:
| Name | Type | Description |
|---|---|---|
timeStep |
number | Time step, this should not vary. |
velocityIterations? |
number | - |
positionIterations? |
number | - |
Returns: void