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