New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ecsengine

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ecsengine

Simple entity component system (ECS) engine for JavaScript

  • 0.3.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

  1. Create an instance of engine
import { Engine } from 'ecsengine'
const engine = new Engine()
  1. 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.

  1. 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()
}
  1. 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

  1. Define class for your entity:
class GameObject extends Entity{
  constructor(){
    super()
    this.add(PhysicComponent, {})
    this.add(PositionComponent, {})
  }
}
  1. 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)

FAQs

Package last updated on 09 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc