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 p5.js instance.
This class extends `planck.World` and adds some p5play specific
features.
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
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.
Optionally you can specify a group to search.
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.
Optionally you can specify a group to search.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
||
y |
Number
|
||
group |
Group
|
<optional> |
the group to search |
cameraActiveWhenDrawn |
Boolean
|
<optional> |
if true, only sprites that were drawn when the camera was active will be returned |
resize(w, h)
Resizes the world to the given width and height and resets the origin.
Used when the canvas is created or resized.
Parameters:
Name | Type | Description |
---|---|---|
w |
Number
|
|
h |
Number
|
step(timeStep, velocityIterations, positionIterations)
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 p5.js draw
loop, unless it was already called inside the draw loop.
Parameters:
Name | Type | Description |
---|---|---|
timeStep |
Number
|
time step in seconds |
velocityIterations |
Number
|
|
positionIterations |
Number
|