diff --git a/README.md b/README.md index bbd5db10..3ed1ece1 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,11 @@ class MoveSystem extends es.EntityProcessingSystem { // 因为在构造函数中有一个Matcher匹配器,在你初始化MoveSystem的时候需要你传入匹配的对象. 见下方如何定义匹配带MoveComponent的匹配器 // 该方法每帧都会执行,请确保您的操作尽可能的小或者在使用大数据时采用缓存的方法进行获取操作 + const moveComponent = entity.getComponent(MovementComponent); + if (!moveComponent.enabled) + return; + + // 根据moveComponent的数据执行移动的逻辑 } } ``` diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index dceddcdb..be9d3bf8 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -375,12 +375,12 @@ declare module es { * 检查实体是否具有该组件 * @param type */ - hasComponent(type: any): boolean; + hasComponent(type: new (...args: any[]) => T): boolean; /** * 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。 * @param type */ - getOrCreateComponent(type: any): T; + getOrCreateComponent(type: new (...args: any[]) => T): T; /** * 获取typeName类型的所有组件,但不使用列表分配 * @param typeName diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 44b49aa0..a55e23d6 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -424,7 +424,7 @@ module es { * 检查实体是否具有该组件 * @param type */ - public hasComponent(type) { + public hasComponent(type: new (...args) => T) { return this.components.getComponent(type, false) != null; } @@ -432,7 +432,7 @@ module es { * 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。 * @param type */ - public getOrCreateComponent(type) { + public getOrCreateComponent(type: new (...args) => T) { let comp = this.components.getComponent(type, true); if (!comp) { comp = this.addComponent(new type());