在实体管理器中添加一个实体。
entityManager.add(entity);
entity
:待添加的实体对象。该方法没有返回值。
var entityManager = new Yuka.EntityManager();
// 定义实体
class Box extends Yuka.Entity {
constructor() {
super();
this.width = Math.random() * 10 + 10;
this.height = Math.random() * 10 + 10;
this.depth = Math.random() * 10 + 10;
}
}
// 创建两个实体
var box1 = new Box();
var box2 = new Box();
// 将实体添加到实体管理器
entityManager.add(box1);
entityManager.add(box2);
// 获取实体管理器中的所有实体
var entities = entityManager.getEntities();
console.log(entities); // [box1, box2]
TypeError
异常。