Skip to content

Instantly share code, notes, and snippets.

@audinue
Last active July 23, 2017 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audinue/e7d6b5b48605027e4c3649cef0d24b70 to your computer and use it in GitHub Desktop.
Save audinue/e7d6b5b48605027e4c3649cef0d24b70 to your computer and use it in GitHub Desktop.
Javascript Simple Entity Component System Engine

Javascript Simple Entity Component System Engine

Entities represented by plain objects.

const player = {}

Components represented by entity properties.

The problem with this approach is that string based component keys are not modular.

const player = {
  bounds: {
    x: 0,
    y: 0,
    width: 30,
    height: 30
  },
  fill: 'red'
}

Systems represented by callbacks or plain objects with system lifecycle hooks.

function RectangleRendering (engine) {
}

// or

class RectangleRendering {
  add (engine) {
  }
  run (engine) {
  }
  remove (engine) {
  }
}

To query entities, one can use their component names.

function RectangleRendering (engine) {
  engine.each(['bounds', 'fill'], (bounds, fill, entity) => {    
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment