Skip to content

ECS Framework API v2.2.13


ECS Framework API / getComponents

Function: getComponents()

getComponents<T>(entity, ...types): { [K in string | number | symbol]: null | ComponentInstance<T[K<K>]> }

Defined in: packages/core/src/ECS/TypedEntity.ts:77

批量获取组件

Type Parameters

T

T extends readonly ComponentConstructor[]

Parameters

entity

Entity

实体实例

types

...T

组件类型构造函数数组

Returns

{ [K in string | number | symbol]: null | ComponentInstance<T[K<K>]> }

组件实例元组,每个元素可能为null

Example

typescript
const [pos, vel, health] = getComponents(entity, Position, Velocity, Health);
if (pos && vel && health) {
    pos.x += vel.dx;
}

Released under the MIT License.