Files
esengine/docs/getting_start.md
2021-07-23 14:09:53 +08:00

70 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 如何开始
## 初始化框架
```typescript
// 参数为false则开启debug模式
es.Core.create(false);
```
## 分发帧事件
```typescript
// 放置于引擎每帧更新处
// dt为可选参数传入引擎的deltaTime代替框架内的es.Time.deltaTime
es.Core.emitter.emit(es.CoreEvents.frameUpdated, dt);
```
> 尽可能使用引擎的dt以免再游戏暂停继续时由于dt导致的跳帧问题
> **您还需要一个默认的场景以使得游戏可以进行使用ecs框架以及物理类或tween系统**
## 创建场景类
场景类需要继承框架中的 `es.Scene`
```typescript
export class MainScene extends es.Scene {
/**
* 可重写方法从contructor中调用这个函数
*/
initialize() {
console.log('initialize');
}
/**
* 可重写方法。当Core将这个场景设置为活动场景时调用
*/
onStart() {
console.log('onStart');
}
/**
* 可重写方法。当Core把这个场景从活动槽中移除时调用。
*/
unload() {
console.log('unload');
}
/**
* 可重写方法。
*/
update() {
// 如果重写update方法 一定要调用该方法
// 不调用将导致实体无法加入/组件无法更新
super.update();
}
}
```
要想激活该场景需要通过核心类 `Core` 来设置当前 `MainScene` 为使用的场景
```typescript
es.Core.scene = new MainScene();
```
# 下一章节
- [创建实体与组件](create_entity_component.md)
- [创建系统](system.md)
- [全局时间Time](time.md)
- [协程Coroutine](coroutine.md)