goo2d 0.1.1 copy "goo2d: ^0.1.1" to clipboard
goo2d: ^0.1.1 copied to clipboard

The 2D renderer for the good game engine: transforms, camera, sprites, nine-slice borders, colliders and mouse picking, on top of the good kernel, which it re-exports.

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 {
  late final DataPointer<double> speed;
  late final Sprite sprite;

  @override
  void describeStruct(DataDescriptor data) {
    super.describeStruct(data);
    speed = data.hasFloat64(220);
  }

  @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.

1
likes
160
points
153
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

The 2D renderer for the good game engine: transforms, camera, sprites, nine-slice borders, colliders and mouse picking, on top of the good kernel, which it re-exports.

Homepage
Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

flutter, good, meta, vector_math

More

Packages that depend on goo2d