new World()
Look at the World reference pages before reading these docs.
A `world` object is created automatically by p5play. There can only
be one world per sketch (instance of p5 or q5).
This class extends `planck.World` and adds some p5play specific
features.
Extends
- planck.World
Classes
Members
allowSleeping :Boolean
"Sleeping" sprites get temporarily ignored during physics
simulation. A sprite starts "sleeping" when it stops moving and
doesn't collide with anything that it wasn't already touching.
This is an important performance optimization that you probably
shouldn't disable for every sprite in the world.
Type:
-
Boolean
gravity :Object
Gravity force vector that affects all dynamic physics colliders.
Properties:
Name | Type | Description |
---|---|---|
x |
Number
|
|
y |
Number
|
Type:
-
Object
realTime :Number
The real time in seconds since the world was created, including
time spent paused.
Type:
-
Number
timeScale :Number
A time scale of 1.0 represents real time.
Accepts decimal values between 0 and 2.
Type:
-
Number
velocityThreshold :Number
The lowest velocity an object can have before it is considered
to be at rest.
Adjust the velocity threshold to allow for slow moving objects
but don't have it be too low, or else objects will never sleep,
which will hurt performance.
Type:
-
Number
Methods
getSpriteAt(x, y, groupopt) → {Sprite}
Returns the sprite at the specified position
on the top most layer, drawn when the camera was on.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
||
y |
Number
|
||
group |
Group
|
<optional> |
the group to search |
getSpritesAt(x, y, groupopt, cameraActiveWhenDrawnopt) → {Array:.<Sprite:>}
Returns the sprites at a position, ordered by layer.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
Number
|
|||
y |
Number
|
|||
group |
Group
|
<optional> |
limit results to a specific group, allSprites by default | |
cameraActiveWhenDrawn |
Boolean
|
<optional> |
true | limit results to sprites drawn when the camera was active, true by default |
rayCast(startPos, direction, maxDistance) → {Sprite}
Finds the first sprite that intersects a ray (line),
excluding any sprites that intersect with the starting point.
Can also be given a starting position and a maximum end position.
Parameters:
Name | Type | Description |
---|---|---|
startPos |
Object
|
starting position of the ray cast |
direction |
Number
|
direction of the ray |
maxDistance |
Number
|
max distance the ray should check |
rayCastAll(startPos, direction, maxDistance, limiteropt) → {Array:.<Sprite:>}
Finds sprites that intersect a line (ray), excluding any sprites
that intersect the starting point.
Can also be given a starting position and a maximum end position.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
startPos |
Object
|
starting position of the ray cast | |
direction |
Number
|
direction of the ray | |
maxDistance |
Number
|
max distance the ray should check | |
limiter |
function
|
<optional> |
limiter function that's run each time the ray intersects a sprite, return true to stop the ray |
Returns:
- Type:
-
Array:.<Sprite:>
An array of sprites that the ray cast hit, sorted by distance. The sprite closest to the starting point will be at index 0.
step(timeStepopt, velocityIterationsopt, positionIterationsopt)
Performs a physics simulation step that advances all sprites'
forward in time by 1/60th of a second if no timeStep is given.
This function is automatically called at the end of the draw
loop, unless it was already called inside the draw loop.
Decreasing velocityIterations and positionIterations will improve
performance but decrease simulation quality.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
timeStep |
Number
|
<optional> |
time step in seconds |
velocityIterations |
Number
|
<optional> |
8 by default |
positionIterations |
Number
|
<optional> |
3 by default |