# ecs-lite **Repository Path**: aodazhang/ecs-lite ## Basic Information - **Project Name**: ecs-lite - **Description**: 基于 ts 实现的纯 ecs 库,可用于学习交流及 H5 游戏开发!🚀 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: https://aodazhang.com/ecs-lite - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-11-25 - **Last Updated**: 2023-12-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🚀 ecs-lite ![gzip](https://img.shields.io/badge/gzip-38kb-blue?style=flat-square) ![coverage](https://img.shields.io/badge/coverage-73.96%25-ff69b4?style=flat-square) 基于 ts 实现的纯 ecs 库,可用于学习交流及 H5 游戏开发! ### 🚚 文档 更多内容请参考 [文档](https://aodazhang.com/ecs-lite),您可以关注 [changelog](https://gitee.com/aodazhang/ecs-lite/blob/master/CHANGELOG.md) 获取最新进展! [示例:flappy bird](https://project.aodazhang.com/ecs-lite) ### 🛠 安装与使用 #### 1.安装 ```shell npm i ecs-lite -S # or yarn add ecs-lite -S ``` #### 2.使用 ```javascript 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() ```