0.3.7 • Published 6 years ago
ecsengine v0.3.7
THIS LIBRARY IS CURRENTLY IN ACTIVE DEVELOPMENET, THINGS WILL SIGNIFICANTLY CHANGE IN NEAREST FUTURE!
ecsengine
Simple Entity-Component-System (ECS) engine for JavaScript written in TypeScript.
Install
npm install ecsengine --save
Usage
- Create an instance of engine
import { Engine } from 'ecsengine'
const engine = new Engine()
- Define your components. The components are just to store data. It does not have to contain any logic. According to ECS paradigm - you store all your logic in System's code.
class PositionComponent extends Component{
x: number = 0
y: number = 0
z: number = 0
}
class PhysicComponent extends Component{}
Component may be an empty class - just to point that entity with that component have some behavior.
- Define component group for system. Each system interested in work with entity that have some set of components.
class PhysicComponentGroup{
position: PositionComponent = new PositionComponent()
physic: PhysicComponent = new PhysicComponent()
}
- Define system and describe your logic there:
@componentsGroup(PhysicComponent)
class PhysicSystem extends System<PhysicComponentGroup>{
execute(content: PhysicComponentGroup){
content.position.x -= 9.8
}
}
Also note that this code use decorators so you must have "experimentalDecorators": true,
in your tsconfig.json
- Define class for your entity:
class GameObject extends Entity{
constructor(){
super()
this.add(PhysicComponent, {})
this.add(PositionComponent, {})
}
}
- Add system and entity to engine and run it:
const gameObject = new GameObject()
engine.addSystem(PhysicSystem)
engine.addEntity(gameObject)
setInterval(()=>{
engine.update()
console.log(gameObject.components.get(PositionComponent))
}, 100)
0.3.7
6 years ago
0.3.6
6 years ago
0.3.5
6 years ago
0.3.4
6 years ago
0.3.3
6 years ago
0.3.2
6 years ago
0.3.1
6 years ago
0.3.0
6 years ago
0.2.0
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.13
6 years ago
0.0.12
6 years ago
0.0.11
6 years ago
0.0.10
6 years ago
0.0.9
6 years ago
0.0.8
6 years ago
0.0.7
6 years ago
0.0.6
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago