3 Serpentity is a simple entity framework inspired by [Ash][ash].
9 ## Instantiating an engine
11 var engine = 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 var entity = new Serpentity.Entity();
34 All the behavior is added through components
36 ## Creating Components
38 Components define data that we can add to an entity. This data will
39 eventually be consumed by "Systems"
41 Class("PositionComponent").inherits(Serpentity.Component)({
48 You can add components to entities by using the add method:
50 entity.add(new PositionComponent());
53 Systems can refer to entities by requesting nodes.
57 Nodes are sets of components that you define, so your system can require
58 entities that always follow the API defined in the node.
60 Class("MovementNode").inherits(Serpentity.Node)({
62 position : PositionComponent,
63 motion : MotionComponent
67 You can then request an array of all the nodes representing entities
68 that comply with that API
70 engine.getNodes(MovementNode);
74 Systems are called on every update, and they use components through nodes.
76 Class("TestSystem").inherits(Serpentity.System)({
78 added : function added(engine){
79 this.nodeList = engine.getNodes(MovementNode);
81 removed : function removed(engine){
82 this.nodeList = undefined;
84 update : function update(dt){
85 this.nodeList.forEach(function (node) {
86 console.log("Current position is: " + node.position.x + "," + node.position.y);
94 Just run `engine.update(dt)` in your game loop :D
96 ## Checking it in the frontend (dev).
98 You can link the bower package to test it out locally.
99 Spawn a python server (`python -m SimpleHTTPServer`) to see
100 the test page in `http://localhost:8000/browser_test/`
105 * Removing components
106 * Implement the ashteroids demo (Serpentoids)
107 * Actually check performance
109 [ash]: http://www.ashframework.org/