goo2d

Game Overdrive On 2D. A 2D game engine for Flutter that runs your simulation on its own isolate at a fixed timestep, and keeps components in native memory so the frame loop does not allocate.

flutter pub add goo2d

That is the only dependency you need. goo2d re-exports the good kernel, so one import covers both.

What a game looks like

An entity kind is a struct of columns. speed here is a column, and [entity] indexes a row in it:

import 'package:goo2d/goo2d.dart';

class Player extends EntityStruct
    with Transform2D, WorldTransform2D, Renderable2D {
  final speed = Field.float64(220);
  late final Sprite sprite;

  @override
  void describeSprites(SpriteDescriptor descriptor) {
    super.describeSprites(descriptor);
    sprite = descriptor.has(width: 64, height: 64, color: 0xFFCC8844);
  }
}

A system queries for the entities it cares about and writes to their columns:

class PlayerSystem extends GameSystem with FixedTickable {
  late final Query players;

  @override
  void describeQuery(QueryDescriptor descriptor) {
    super.describeQuery(descriptor);
    players = descriptor.query().withAll(Transform2D, Player).build();
  }

  @override
  void onFixedUpdate() {
    final dt = game.fixedTimeStep.inMicroseconds / 1000000.0;
    for (final group in players.groups()) {
      final transform = group.get<Transform2D>();
      for (final entity in group) {
        transform.transformOffsetX[entity] += 60 * dt;
      }
    }
  }
}

Declare what exists and what runs, then show it:

class MyGameState extends GameState2D<MyGame> {
  @override
  void describeSystems(SystemDescriptor descriptor) {
    super.describeSystems(descriptor);
    descriptor.has(PlayerSystem());
  }

  @override
  void onMounted() => loadScene(MainScene());
}
GameView(camera: game.defaultCamera)

Next

Transforms, camera, sprite rendering, colliders and mouse picking work today. Audio assets load, but there is no audio backend yet, and the web is unsupported because the kernel needs dart:ffi and isolates. What works today.

Libraries

goo2d
The 2D good engine: everything needed to build a 2D game.