3 Serpentity is a simple entity framework inspired by [Ash][ash].
7 import Serpentity from '@serpentity/serpentity';
9 ## Instantiating an engine
11 const engine = new Serpentity();
13 Add entities or systems, systems are added with a priority (the smaller
14 the number, the earlier it will be called):
16 engine.addEntity(entityFactory());
17 engine.addSystem(new GameSystem(), priority);
23 Remove entities or systems:
25 engine.removeEntity(entityReference);
26 engine.removeSystem(systemReference);
30 Entities are the basic object of Serpentity, and they do nothing.
32 import { Entity } from '@serpentity/serpentity';
33 const entity = new Entity();
35 All the behavior is added through components
37 ## Creating Components
39 Components define data that we can add to an entity. This data will
40 eventually be consumed by "Systems"
42 import { Component } from '@serpentity/serpentity';
43 const PositionComponent = class PositionComponent extends Component {
53 You can add components to entities by using the add method:
55 entity.addComponent(new PositionComponent());
58 Systems can refer to entities by requesting nodes.
62 Nodes are sets of components that you define, so your system can require
63 entities that always follow the API defined in the node.
65 import { Node } from '@serpentity/serpentity';
66 const MovementNode = class MovementNode extends Node;
67 MovementNode.position = PositionComponent;
68 MovementNode.motion = MotionComponent;
70 You can then request an array of all the nodes representing entities
71 that comply with that API
73 engine.getNodes(MovementNode);
77 Systems are called on every update, and they use components through nodes.
79 import { System } from '@serpentity/serpentity';
80 const TestSystem = class TestSystem extends System {
83 this.nodeList = engine.getNodes(MovementNode);
88 this.nodeList = undefined;
93 for (const node of this.nodeList) {
94 console.log(`Current position is: ${node.position.x},${node.position.y}`);
101 Just run `engine.update(dt)` in your game loop :D
103 [ash]: http://www.ashframework.org/