UNPKG

ecsjs

Version:

An entity component system library for JavaScript

77 lines (54 loc) 1.82 kB
# Entity Component System for Javascript [![Pipeline status](https://gitlab.com/ecsjs/ecs/badges/master/pipeline.svg)](https://gitlab.com/ecsjs/ecs/-/pipelines) [![NPM version](https://img.shields.io/npm/v/ecsjs.svg)](https://www.npmjs.org/package/ecsjs) [![NPM downloads](https://img.shields.io/npm/dm/ecsjs.svg)](https://npmjs.org/package/ecsjs "View this project on NPM") [![BuyMeACoffee](https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png)](https://www.buymeacoffee.com/peterf) An entity component system library for JavaScript ## Install `npm install --save ecsjs` ## Documentation - [Cheat Sheet](https://gitlab.com/ecsjs/ecs/-/blob/master/docs/cheat-sheet.md) - [Reference Documentation](https://ecsjs.gitlab.io/ecs) ## Examples - [Classic Asteroids](https://gitlab.com/ecsjs/example-astroids) - [Classic Kung Fu](https://gitlab.com/ecsjs/example-kungfu) - [Misc Examples](https://gitlab.com/ecsjs/ecs-examples) #### Browser ```html <script type="application/javascript" src="./some-path/ecs.js"></script> <script> // define a component class Position { constructor(x, y) { this.x = x this.y = y } } // register the component ecs.register(Position) // create an entity const entityId = ecs.getNextId() // add or update the entity data ecs.set(entityId, new Position(25, 25)) </script> ``` #### Module import ```js import { ecs } from 'ecsjs' // define a component class Position { constructor(x, y) { this.x = x this.y = y } } // register the component ecs.register(Position) // create an entity const entityId = ecs.getNextId() // add or update the entity data ecs.set(entityId, new Position(25, 25)) ``` ## License Licensed under GNU GPL v3 Copyright &copy; 2013+ [contributors](https://gitlab.com/ecsjs/ecs/-/graphs/master)