Skip to content

ECS Framework API v2.2.13


ECS Framework API / hasComponents

Function: hasComponents()

hasComponents(entity, ...types): boolean

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

检查实体是否拥有所有指定的组件

Parameters

entity

Entity

实体实例

types

...ComponentConstructor[]

组件类型构造函数数组

Returns

boolean

如果拥有所有组件返回true,否则返回false

Example

typescript
if (hasComponents(entity, Position, Velocity)) {
    const pos = entity.getComponent(Position)!;
    const vel = entity.getComponent(Velocity)!;
}

Released under the MIT License.