Class: PositionSystem
Position system. Does not do any updates but has some helpers for querying entities based on their position.
Hierarchy
Constructors
constructor
• new PositionSystem(): PositionSystem
Returns
Overrides
Properties
aspects
• Protected
aspects: Map
<string
, Position
>
Inherited from
name
• Readonly
name: string
Name of the system for debugging purposes.
Inherited from
Methods
beginFrame
▸ beginFrame(dt
, engine
, steps
): void
Overridable method called in the beginning of each frame.
Parameters
Name | Type | Description |
---|---|---|
dt |
number |
Time elapsed since last frame |
engine |
Engine |
Engine instance |
steps |
number |
Total number of steps for this frame |
Returns
void
Inherited from
destroy
▸ destroy(): void
Overridable method called when the engine is destroyed. Call super
to clear the protected
aspects map.
Returns
void
Inherited from
endFrame
▸ endFrame(dt
, engine
, steps
): void
Overridable method called in the end of each frame.
Parameters
Name | Type | Description |
---|---|---|
dt |
number |
Time elapsed since last frame |
engine |
Engine |
Engine instance |
steps |
number |
Total number of steps for this frame |
Returns
void
Inherited from
findClosestEntity
▸ findClosestEntity(point
, entities
): Object
Find the closest entity for a point from a list of entities.
Parameters
Name | Type | Description |
---|---|---|
point |
Point |
Coordinates to look from |
entities |
string [] |
List of entities to test |
Returns
Object
Name | Type |
---|---|
entity |
null | string |
position |
null | Position |
getAspect
▸ getAspect<T
>(type
, entity
): undefined
| T
Get typed aspect bound to the entity. If the entity has an aspect in the system but it is
not of the specified type the return value will be undefined
.
Type parameters
Name | Type |
---|---|
T |
extends Position |
Parameters
Name | Type | Description |
---|---|---|
type |
Type <T > |
Type of the aspect |
entity |
string |
Entity to get the aspect from |
Returns
undefined
| T
Inherited from
▸ getAspect(entity
): undefined
| Position
Get the aspect bound to the entity.
Parameters
Name | Type | Description |
---|---|---|
entity |
string |
Entity to get the aspect from |
Returns
undefined
| Position
Inherited from
getAspects
▸ getAspects(): Map
<string
, Position
>
Get access to the aspect map for iterating entities.
Do not modify the returned map directly!
Always use setAspect
and removeAspect
to modify the aspect map to ensure that the
overloaded versions of these functions are called properly. Same warning applies for direct
access to the protected this.aspects
in the derived sub-systems.
Returns
Map
<string
, Position
>
Inherited from
getEntities
▸ getEntities(): string
[]
Get a list of all entities that have aspects in this system.
Returns
string
[]
Deprecated
This is a very unoptimal way to access the aspects. You should use getAspects
(or this.aspects
inside System
scope) to access the entities.
Inherited from
removeAspect
▸ removeAspect(entity
): void
Remove the aspect bound to the entity.
Parameters
Name | Type | Description |
---|---|---|
entity |
string |
Entity to remove the aspect from |
Returns
void
Inherited from
requireAspect
▸ requireAspect<T
>(type
, entity
): T
Get typed aspect bound to the entity. If the aspect is not found or if the entity has an aspect in the system but it is not of the specified type an exception is thrown.
Type parameters
Name | Type |
---|---|
T |
extends Position |
Parameters
Name | Type | Description |
---|---|---|
type |
Type <T > |
Type of the aspect |
entity |
string |
Entity to get the aspect from |
Returns
T
Inherited from
▸ requireAspect(entity
): Position
Get the aspect bound to the entity. If the aspect is not found an exception is thrown.
Parameters
Name | Type | Description |
---|---|---|
entity |
string |
Entity to get the aspect from |
Returns
Inherited from
setAspect
▸ setAspect(entity
, aspect
): void
Set the entity’s aspect in this sub-system. Usually the aspect is created with
new AspectT(...)
and then passed to setAspect
.
Parameters
Name | Type | Description |
---|---|---|
entity |
string |
Entity to set the aspect for |
aspect |
Position |
The aspect to set |
Returns
void
Inherited from
step
▸ step(dt
, engine
, step
, steps
): void
Overridable method called n times each frame depending on how much time has elapsed since the last frame.
Parameters
Name | Type | Description |
---|---|---|
dt |
number |
The fixed time step |
engine |
Engine |
Engine instance |
step |
number |
Step counter for the frame |
steps |
number |
Total number of steps for this frame |
Returns
void