fast_ecs 0.0.0 copy "fast_ecs: ^0.0.0" to clipboard
fast_ecs: ^0.0.0 copied to clipboard

outdated

Simple and fast Entity-Component-System (ECS) library written in Dart.

example/README.md

Fast ECS Examples #

Components #

Creating a [Components] class

class VelocityComponent extends Component {
  double velocity = 2;
}

class TransformComponent extends Component {
  double rotation = 0.0;
  double scale = 0.5;
}

Systems #

Creating a [RotationSystem] class

class RotationSystem extends UpdateEcsSystem {
  late List<Component> transformComponents; // quick link
  late List<Component> velocityComponents; // quick link

  @override
  void init(ecs, Signature signature) {
    transformComponents = ecs.getComponentList<TransformComponent>();
    velocityComponents = ecs.getComponentList<VelocityComponent>();
  }

  @override
  void update(double deltaTime, SetEntity entities) {
    for (var i = 0; i < entities.size; i++) {
      Entity entity = entities.get(i);
      TransformComponent transform = transformComponents[entity] as TransformComponent;
      VelocityComponent rotation = velocityComponents[entity] as VelocityComponent;
      transform.rotation += rotation.velocity * deltaTime;
    }
  }
}

Ecs #

Creating a [Ecs] class

Ecs ecs = Ecs(maxEntity: maxEntity, maxComponents: 8);
// register components
ComponentId transformId = ecs.registerComponent<TransformComponent>((index) => TransformComponent(), maxEntity);
ComponentId velocityId = ecs.registerComponent<VelocityComponent>((index) => VelocityComponent(), maxEntity);
var rotationSystemSignature = ecs.createSignature([transformId, velocityId]);
// register [RotationSystem] with signature
ecs.registerSystem<RotationSystem>(() => RotationSystem(), signature: rotationSystemSignature);

Entity #

Creating a [Entity]

Entity entity = ecs.createEntity();
ecs.addComponent(transformId, entity);
ecs.addComponent(velocityId, entity);

Use #

update ECS

//
ecs.update(deltaTime);
4
likes
0
pub points
1%
popularity

Publisher

unverified uploader

Simple and fast Entity-Component-System (ECS) library written in Dart.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on fast_ecs