0 Star 0 Fork 1

嗷大张 / ecs-lite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
嗷大张 提交于 2023-12-10 21:37 . docs(all): 更新readme.md

🚀 ecs-lite

gzip coverage

基于 ts 实现的纯 ecs 库,可用于学习交流及 H5 游戏开发!

🚚 文档

更多内容请参考 文档,您可以关注 changelog 获取最新进展!

示例:flappy bird

🛠 安装与使用

1.安装

npm i ecs-lite -S
# or
yarn add ecs-lite -S

2.使用

import { Component, System, World } from 'ecs-lite'

// 1.定义组件
class Position extends Component {
  constructor(x, y) {
    super()
    this.x = x
    this.y = y
  }
}

// 2.定义系统
class PositionSystem extends System {
  constructor() {
    super()
  }
  update(world) {
    for (const [entity, componentMap] of world.view(Position)) {
      const position = componentMap.get(Position)
      position.x += 10
      console.log('组件实例', position)
    }
  }
}

// 3.初始化实体、组件、系统
const world = new World()
world.addEntityWithComponents(world.createEntity('car'), new Position(0, 100))
world.addSystem(new PositionSystem())

// 4.启动world
world.start()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aodazhang/ecs-lite.git
git@gitee.com:aodazhang/ecs-lite.git
aodazhang
ecs-lite
ecs-lite
master

搜索帮助