Merge pull request #25 from esengine/develop

#16 新增createEntityAsync方法
This commit is contained in:
YHH
2020-08-08 09:51:24 +08:00
committed by GitHub
9 changed files with 42 additions and 13 deletions
+1
View File
@@ -370,6 +370,7 @@ declare module es {
getPostProcessor<T extends PostProcessor>(type: any): T;
removePostProcessor(postProcessor: PostProcessor): void;
createEntity(name: string): Entity;
createEntityAsync(name: string): Promise<Entity>;
addEntity(entity: Entity): Entity;
destroyAllEntities(): void;
findEntity(name: string): Entity;
+8 -1
View File
@@ -1603,6 +1603,7 @@ var es;
childClone.transform.parent = this.transform;
}
};
Entity._idGenerator = 0;
return Entity;
}());
es.Entity = Entity;
@@ -1755,9 +1756,15 @@ var es;
var entity = new es.Entity(name);
return this.addEntity(entity);
};
Scene.prototype.createEntityAsync = function (name) {
var _this = this;
return new Promise(function (resolve) {
resolve(_this.createEntity(name));
});
};
Scene.prototype.addEntity = function (entity) {
if (this.entities.buffer.contains(entity))
console.warn("You are attempting to add the same entity to a scene twice: " + entity);
console.warn("\u60A8\u8BD5\u56FE\u5C06\u540C\u4E00\u5B9E\u4F53\u6DFB\u52A0\u5230\u573A\u666F\u4E24\u6B21: " + entity);
this.entities.add(entity);
entity.scene = this;
for (var i = 0; i < entity.transform.childCount; i++)
File diff suppressed because one or more lines are too long
+10 -7
View File
@@ -11,13 +11,17 @@ module scene {
public async onStart() {
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
let bg = this.createEntity("bg");
this.createEntityAsync("bg").then(bg => {
bg.addComponent(new component.PlayerController());
bg.addComponent(new es.Mover());
bg.addComponent(new es.ScrollingSpriteRenderer(sprite)).setGapXY(new es.Vector2(10, 0));
bg.addComponent(new es.BoxCollider());
bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200);
this.camera.follow(bg, es.CameraStyle.lockOn);
});
// bg.addComponent(new es.SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
bg.addComponent(new component.PlayerController());
bg.addComponent(new es.Mover());
bg.addComponent(new es.ScrollingSpriteRenderer(sprite)).setGapXY(new es.Vector2(10, 0));
bg.addComponent(new es.BoxCollider());
bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200);
for (let i = 0; i < 20; i++) {
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
@@ -27,7 +31,6 @@ module scene {
player2.addComponent(new es.BoxCollider());
}
this.camera.follow(bg, es.CameraStyle.lockOn);
let pool = new es.ComponentPool<component.SimplePooled>(component.SimplePooled);
let c1 = pool.obtain();
+1
View File
@@ -370,6 +370,7 @@ declare module es {
getPostProcessor<T extends PostProcessor>(type: any): T;
removePostProcessor(postProcessor: PostProcessor): void;
createEntity(name: string): Entity;
createEntityAsync(name: string): Promise<Entity>;
addEntity(entity: Entity): Entity;
destroyAllEntities(): void;
findEntity(name: string): Entity;
+8 -1
View File
@@ -1603,6 +1603,7 @@ var es;
childClone.transform.parent = this.transform;
}
};
Entity._idGenerator = 0;
return Entity;
}());
es.Entity = Entity;
@@ -1755,9 +1756,15 @@ var es;
var entity = new es.Entity(name);
return this.addEntity(entity);
};
Scene.prototype.createEntityAsync = function (name) {
var _this = this;
return new Promise(function (resolve) {
resolve(_this.createEntity(name));
});
};
Scene.prototype.addEntity = function (entity) {
if (this.entities.buffer.contains(entity))
console.warn("You are attempting to add the same entity to a scene twice: " + entity);
console.warn("\u60A8\u8BD5\u56FE\u5C06\u540C\u4E00\u5B9E\u4F53\u6DFB\u52A0\u5230\u573A\u666F\u4E24\u6B21: " + entity);
this.entities.add(entity);
entity.scene = this;
for (var i = 0; i < entity.transform.childCount; i++)
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
module es {
export class Entity {
public static _idGenerator: number;
public static _idGenerator: number = 0;
/**
*
+11 -1
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;