#16 新增createEntityAsync方法

修复entity.id为null
This commit is contained in:
YHH
2020-08-08 09:50:40 +08:00
parent 6a3622a5ef
commit 7cd38ea54e
9 changed files with 42 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
module es {
export class Entity {
public static _idGenerator: number;
public static _idGenerator: number = 0;
/**
* 当前实体所属的场景

View File

@@ -262,13 +262,23 @@ module es {
return this.addEntity(entity);
}
/**
* 将实体添加到此场景,并返回它
* @param name
*/
public createEntityAsync(name: string): Promise<Entity> {
return new Promise<Entity>(resolve => {
resolve(this.createEntity(name));
});
}
/**
* 在场景的实体列表中添加一个实体
* @param entity
*/
public addEntity(entity: Entity) {
if (this.entities.buffer.contains(entity))
console.warn(`You are attempting to add the same entity to a scene twice: ${entity}`);
console.warn(`您试图将同一实体添加到场景两次: ${entity}`);
this.entities.add(entity);
entity.scene = this;