更改示例及新增注释
This commit is contained in:
@@ -21,39 +21,60 @@ module es {
|
||||
}
|
||||
|
||||
/**
|
||||
* 在场景子类中重写这个,然后在这里进行加载。
|
||||
* 在场景设置好之后,但在调用begin之前,从contructor中调用这个函数
|
||||
* 初始化场景,可以在派生类中覆盖
|
||||
*
|
||||
* 这个方法会在场景创建时被调用。您可以在这个方法中添加实体和组件,
|
||||
* 或者执行一些必要的准备工作,以便场景能够开始运行。
|
||||
*/
|
||||
public initialize() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 当Core将这个场景设置为活动场景时,这个将被调用
|
||||
* 开始运行场景时调用此方法,可以在派生类中覆盖
|
||||
*
|
||||
* 这个方法会在场景开始运行时被调用。您可以在这个方法中执行场景开始时需要进行的操作。
|
||||
* 比如,您可以开始播放一段背景音乐、启动UI等等。
|
||||
*/
|
||||
public onStart() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 在场景子类中重写这个,并在这里做任何必要的卸载。
|
||||
* 当Core把这个场景从活动槽中移除时,这个被调用。
|
||||
* 卸载场景时调用此方法,可以在派生类中覆盖
|
||||
*
|
||||
* 这个方法会在场景被销毁时被调用。您可以在这个方法中销毁实体和组件、释放资源等等。
|
||||
* 您也可以在这个方法中执行一些必要的清理工作,以确保场景被完全卸载。
|
||||
*/
|
||||
public unload() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始场景,初始化物理系统、启动实体处理器等
|
||||
*
|
||||
* 这个方法会启动场景。它将重置物理系统、启动实体处理器等,并调用onStart方法。
|
||||
*/
|
||||
public begin() {
|
||||
// 重置物理系统
|
||||
Physics.reset();
|
||||
|
||||
// 启动实体处理器
|
||||
if (this.entityProcessors != null)
|
||||
this.entityProcessors.begin();
|
||||
|
||||
// 标记场景已开始运行并调用onStart方法
|
||||
this._didSceneBegin = true;
|
||||
this.onStart();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束场景,清除实体、场景组件、物理系统等
|
||||
*
|
||||
* 这个方法会结束场景。它将移除所有实体并调用它们的onRemovedFromScene方法,清除物理系统,结束实体处理器等,并调用unload方法。
|
||||
*/
|
||||
public end() {
|
||||
// 标记场景已结束运行
|
||||
this._didSceneBegin = false;
|
||||
|
||||
// 移除所有实体并调用它们的onRemovedFromScene方法
|
||||
this.entities.removeAllEntities();
|
||||
|
||||
for (let i = 0; i < this._sceneComponents.length; i++) {
|
||||
@@ -61,30 +82,38 @@ module es {
|
||||
}
|
||||
this._sceneComponents.length = 0;
|
||||
|
||||
// 清除物理系统
|
||||
Physics.clear();
|
||||
|
||||
// 结束实体处理器
|
||||
if (this.entityProcessors)
|
||||
this.entityProcessors.end();
|
||||
|
||||
// 调用卸载方法
|
||||
this.unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新场景,更新实体组件、实体处理器等
|
||||
*/
|
||||
public update() {
|
||||
// 更新我们的列表,以防它们有任何变化
|
||||
// 更新实体列表
|
||||
this.entities.updateLists();
|
||||
|
||||
// 更新场景组件
|
||||
for (let i = this._sceneComponents.length - 1; i >= 0; i--) {
|
||||
if (this._sceneComponents[i].enabled)
|
||||
this._sceneComponents[i].update();
|
||||
}
|
||||
|
||||
// 更新我们的实体解析器
|
||||
// 更新实体处理器
|
||||
if (this.entityProcessors != null)
|
||||
this.entityProcessors.update();
|
||||
|
||||
// 更新我们的实体组
|
||||
// 更新实体组
|
||||
this.entities.update();
|
||||
|
||||
|
||||
// 更新实体处理器的后处理方法
|
||||
if (this.entityProcessors != null)
|
||||
this.entityProcessors.lateUpdate();
|
||||
}
|
||||
@@ -193,8 +222,8 @@ module es {
|
||||
|
||||
/**
|
||||
* 返回提一个具有该标记的实体
|
||||
* @param tag
|
||||
* @returns
|
||||
* @param tag
|
||||
* @returns
|
||||
*/
|
||||
public findEntityWithTag(tag: number): Entity {
|
||||
return this.entities.entityWithTag(tag);
|
||||
@@ -218,8 +247,8 @@ module es {
|
||||
|
||||
/**
|
||||
* 返回场景中包含特定组件的实体列表
|
||||
* @param type
|
||||
* @returns
|
||||
* @param type
|
||||
* @returns
|
||||
*/
|
||||
public findEntitiesOfComponent(...types): Entity[] {
|
||||
return this.entities.findEntitiesOfComponent(...types);
|
||||
@@ -232,7 +261,7 @@ module es {
|
||||
public addEntityProcessor(processor: EntitySystem) {
|
||||
processor.scene = this;
|
||||
this.entityProcessors.add(processor);
|
||||
|
||||
|
||||
processor.setUpdateOrder(this.entityProcessors.count - 1);
|
||||
this.entityProcessors.clearDirty();
|
||||
return processor;
|
||||
|
||||
Reference in New Issue
Block a user