Constructor
new Chunk(space, x, y)
Create a new chunk.
Parameters:
Name | Type | Description |
---|---|---|
space | Space | Parent space |
x | number | Index of chunk along x-axis |
y | number | Index of chunk along y-axis |
- Source
Members
persistent
Check if the chunk, or any of its actors, are persistent.
- Source
persistent
Set the chunk itself to be persistent.
- Source
space
Get the parent space.
- Source
x
Get the index along the x-axis.
- Source
y
Get the index along the y-axis
- Source
Methods
addActor(actor)
Add an actor to the chunk.
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | Actor to add |
addOverlapping(actor)
Add an actor that is overlapping the chunk.
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | Actor to add as overlapping |
checkCollision(actor, pos) → {Object}
Check collision for an actor with other actors.
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | Actor to check collision for |
pos | Vec2 | Position to attempt to move to |
Returns:
Object containing collision result data
- Type:
- Object
drawActors(ctx)
Draw all actors in the chunk.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on |
drawDebug(ctx)
Draw all debugging information for the chunk and its actors.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on |
drawUnits(ctx)
Draw all units within the chunk.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | Canvas context to draw on |
getNearbyActors(ignore, pos, radius) → {Array.<Actor>}
Get all actors near a specified position and within a radius.
Parameters:
Name | Type | Description |
---|---|---|
ignore | Actor | Actor to ignore |
pos | Vec2 | Point to find actors around |
radius | number | Radius to find actors within |
Returns:
Array of actors near point within at radius
- Type:
- Array.<Actor>
getNextID()
Find and set the next actor ID to use.
- Source
getUnit(x, y) → {ChunkUnit|null}
Get a specific unit in the chunk.
Parameters:
Name | Type | Description |
---|---|---|
x | number | Relative index along the x-axis |
y | number | Relative index along the y-axis |
Returns:
Chunk unit at specified position, or null if there is none.
- Type:
- ChunkUnit |
null
getUnitAt(x, y) → {ChunkUnit|null}
Get a chunk unit at a specific position in the space.
Parameters:
Name | Type | Description |
---|---|---|
x | number | Global position along the x-axis |
y | number | Global position along the y-axis |
Returns:
Chunk unit at specified position, or null if there is none.
- Type:
- ChunkUnit |
null
makeUnits()
Generate units within the chunk.
removeOverlapping(actor)
Remove an actor from overlapping with the chunk.
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | Actor to remove as overlapping |
setUnit(x, y, unit)
Set a unit at a specific index.
Parameters:
Name | Type | Description |
---|---|---|
x | number | Relative index along the x-axis |
y | number | Relative index along the y-axis |
unit | ChunkUnit | | Unit to set at indices, or null to remove. |
update(elapsed)
Update the chunk and its actors.
Parameters:
Name | Type | Description |
---|---|---|
elapsed | number | Time since last update cycle in seconds |