dartemis 0.7.1
dartemis: ^0.7.1 copied to clipboard
An Entity System Framework for game development. Based on Artemis.
dartemis #
Content #
About #
dartemis is a Dart port of the Entity System Framework Artemis.
The original has been written in Java by Arni Arent and Tiago Costa and can be found here: http://gamadu.com/artemis with the source available here: https://code.google.com/p/artemis-framework/
Ports for other languages are also available:
Some useful links about what an Entity System/Entity Component System is:
- http://piemaster.net/2011/07/entity-component-artemis/
- http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/
- http://www.richardlord.net/blog/what-is-an-entity-framework
Getting started #
-
Add dartemis to your project by adding it to your pubspec.yaml:
dependencies: dartemis: any -
Import it in your project:
import 'package:dartemis/dartemis.dart'; -
Create a world:
World world = new World(); -
Create entities, add components to them and finally add those entities to the world. Entities with different components will be processed by different systems:
Entity entity = world.createEntity(); entity.addComponent(new Position(world, 0, 0)); entity.addComponent(new Velocity(world, 1, 1)); entity.addToWorld();A
Componentis a pretty simple structure and should not contain any logic:class Position extends Component { num x, y; Position(this.x, this.y); }Or if you want to use a
PooledComponent(see dartemis_transformer if you want to use them without having to write this code):class Position extends PooledComponent { num x, y; Position._(); factory Position(num x, num y) { Position position = new Pooled.of(Position, _constructor); position.x = x; position.y = y; return position; } static Position _constructor() => new Position._(); }By using a factory constructor and calling the factory constructor in
Pooled, dartemis is able to reuse destroyed components and they will not be garbage collected. For more information about why this is done you might want to read this article: Free Lists For Predictable Game Performance -
Define a systems that should process your entities. The
Aspectdefines which components an entity needs to have in order to be processed by the system:class MovementSystem extends EntityProcessingSystem { Mapper<Position> positionMapper; Mapper<Velocity> velocityMapper; MovementSystem() : super(Aspect.getAspectForAllOf([Position, Velocity])); void initialize() { // initialize your system // Mappers, Systems and Managers have to be assigned here // see dartemis_transformer if you don't want to write this code positionMapper = new Mapper<Position>(Position, world); velocityMapper = new Mapper<Velocity>(Velocity, world); } void processEntity(Entity entity) { Position position = positionMapper[entity]; Velocity vel = velocityMapper[entity]; position.x += vel.x; position.y += vel.y; } } -
Add your system to the world:
world.addSystem(new MovementSystem()); -
Initialize the world:
world.initialize(); -
In your game loop you then process your systems:
world.process();If your game logic requires a delta you can set it by calling:
world.delta = delta;
Documentation #
API #
Example Games using dartemis #
- VDrones - An arcade game (with weekly updates), (Source)
- GitHub Space Off - Originally created for the GitHub Game Off 2012, (Source)
- darteroids - Very simple example included in the example folder of dartemis, (Source)
Add-ons #
- dartemis_toolbox - A set of addons to use with dartemis (like EntityStateMachine, ...) and other libraries for gamedev.
- dartemis_transformer - A transformer to modify and generate code that turns Components into PooledComponents and initializes EntitySystems and Managers.