Constructor
new Space(app, chunkSize, unitSize)
Create a new space.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
app | App | Parent application | |
chunkSize | number | 16 | Number of units per chunk |
unitSize | number | 16 | Number of pixels per unit |
- Source
Members
camera
Get the camera of the space.
- Source
camera
Set the camera of the space.
- Source
events
Get the space's event handler.
- Source
Methods
addActor(actor)
Add an actor to the space.
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | The actor to add |
- Source
addGlobalID(actor)
Add an actor's global identifier to the space (do not call manually).
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | Actor to register identifier for |
- Source
checkCollision(actor, pos) → {Object}
Check collision with all other actors.
Parameters:
Name | Type | Description |
---|---|---|
actor | Actor | The actor to check collision for |
pos | Vec2 | The position to attempt to move to |
- Source
Returns:
Object containing collision result data
- Type:
- Object
chunkAdded(chunk)
Handle a chunk just being added.
Parameters:
Name | Type | Description |
---|---|---|
chunk | Chunk | Chunk that was just added |
- Source
draw(ctx)
Draw the space and its actors.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | The canvas context to draw on |
- Source
drawBackground(ctx)
Draw the background color of the space.
Parameters:
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | The canvas context to draw on |
- Source
fillUnit(x, y, fill, color, walkOn, persistent, regenCache)
Fill a single unit at a specified position.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | number | Position along x-axis | |
y | number | Position along y-axis | |
fill | boolean | true | Whether to fill unit or clear it |
color | Color | | Color, sprite, or sprite identifier for unit | |
walkOn | boolean | false | Whether to allow walking on unit |
persistent | boolean | true | Whether to make parent chunk persistent |
regenCache | boolean | true | Whether to regenerate cached units image |
- Source
fillUnits(x1, y1, x2, y2, fill, color, walkOn)
Fill an area at a specified position.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x1 | number | First position along x-axis | |
y1 | number | First position along y-axis | |
x2 | number | Second position along x-axis | |
y2 | number | Second position along y-axis | |
fill | boolean | true | Whether to fill unit or clear it |
color | Color | | Color, sprite, or sprite identifier for unit | |
walkOn | boolean | false | Whether to allow walking on unit |
- Source
fillUnitsLine(x1, y1, x2, y2, fill, color, walkOn)
Fill a line from one point to another.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x1 | number | First position along x-axis | |
y1 | number | First position along y-axis | |
x2 | number | Second position along x-axis | |
y2 | number | Second position along y-axis | |
fill | boolean | true | Whether to fill unit or clear it |
color | Color | | Color, sprite, or sprite identifier for unit | |
walkOn | boolean | false | Whether to allow walking on unit |
- Source
fillUnitsWalls(x1, y1, x2, y2, fill, color, walkOn)
Fill walls around an area at a specified position.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x1 | number | First position along x-axis | |
y1 | number | First position along y-axis | |
x2 | number | Second position along x-axis | |
y2 | number | Second position along y-axis | |
fill | boolean | true | Whether to fill unit or clear it |
color | Color | | Color, sprite, or sprite identifier for unit | |
walkOn | boolean | false | Whether to allow walking on unit |
- Source
find(id) → {Actor|null}
Get an actor with specified global identifier.
Parameters:
Name | Type | Description |
---|---|---|
id | string | Identifier to search for |
- Source
Returns:
Actor with specified identifier, or null if it does not exist.
- Type:
- Actor |
null
generatePath(start, end) → {Path|null}
Generate a new path in the space.
- Source
Returns:
Generated path, or null if unsuccessful.
- Type:
- Path |
null
getMousePos() → {Vec2}
Get the mouse position relative to the camera and its zoom.
- Source
Returns:
Mouse position in space
- Type:
- Vec2
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 |
- Source
Returns:
Array of actors near point within at radius
- Type:
- Array.<Actor>
getUnit(x, y) → {ChunkUnit|null}
Get a unit at specified indices.
Parameters:
Name | Type | Description |
---|---|---|
x | number | Index along x-axis |
y | number | Index along y-axis |
- Source
Returns:
Chunk unit at specified indices, or null if there is none.
- Type:
- ChunkUnit |
null
getUnitAt(x, y) → {ChunkUnit|null}
Get a unit at a specified position.
Parameters:
Name | Type | Description |
---|---|---|
x | number | Position along x-axis |
y | number | Position along y-axis |
- Source
Returns:
Chunk unit at specified position, or null if there is none.
- Type:
- ChunkUnit |
null
setUnitPattern(x, y, pattern, color, unfilled, filled)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | number | 0 | Position along x-axis |
y | number | 0 | Position along y-axis |
pattern | string | Pattern to use for generation | |
color | Color | | Color, sprite, or sprite identifier for unit | |
unfilled | string | 0 | Character to use for unfilled units |
filled | string | 1 | Character to use for filled units |
- Source
update(elapsed)
Update the space and its actors.
Parameters:
Name | Type | Description |
---|---|---|
elapsed | number | Time since last update |
- Source