Class: PhysicsSystem
Physics system. Handles Box2D world updates and debug drawing.
Debug drawing requires that the debug draw system is registered into the engine.
Hierarchy
-
↳
PhysicsSystem
Constructors
constructor
• new PhysicsSystem(config
): PhysicsSystem
Parameters
Name | Type |
---|---|
config |
PhysicsSystemConfig |
Returns
Overrides
Properties
aspects
• Protected
aspects: Map
<string
, PhysicsObject
>
Inherited from
debugDraw
• Private
Optional
debugDraw: PhysicsDebug
debugDrawEnabled
• debugDrawEnabled: boolean
name
• Readonly
name: string
Name of the system for debugging purposes.
Inherited from
world
• Readonly
world: b2World
worldScale
• Readonly
worldScale: number
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
Overrides
endFrame
▸ endFrame(dt
, engine
): 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 |
Returns
void
Overrides
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 PhysicsObject |
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
| PhysicsObject
Get the aspect bound to the entity.
Parameters
Name | Type | Description |
---|---|---|
entity |
string |
Entity to get the aspect from |
Returns
undefined
| PhysicsObject
Inherited from
getAspects
▸ getAspects(): Map
<string
, PhysicsObject
>
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
, PhysicsObject
>
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
Overrides
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 PhysicsObject |
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
): PhysicsObject
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 |
PhysicsObject |
The aspect to set |
Returns
void
Inherited from
step
▸ step(dt
, engine
): 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 |
Returns
void