2B2D V3



Well, it's been about 5 months since I merged `feature/v3` into the main branch and made Version 3 officially available. I suppose I should mention it somewhere.

"V3? What about V2?" I hear you scream at the glowing box before your eyes. There was a V2, which was largely an internal rewrite. that didn't change much about the public interface of the engine. But V3 makes some significant changes:

The ECS

I've revamped the ECS with a focus on better ergonomics. For example:

const query = update.query([ Bat.name, Position.name ]);
for (const entity of query) {
    const [ bat, position ] = entity.components as [ BatComponent, PositionComponent ];
    // ....
}

now becomes:

const query = update.ecs.query(Bat, Position);
for (const entity of query) {
    const [ bat, position ] = entity.components;
    // ....
}

This makes for a much more pleasant experience around probably the single most frequently used feature of the engine (querying). Also worth noting is that in the above examples, both `bat` and `position` will be strongly typed component classes in TypeScript even without the cast.

Rendering

The rendering engine now makes use of a depth buffer, allowing you to use Depth to determine which sprites render on top of other sprites. The exception to this is partially opaque sprites, which must be batched in the correct order using RenderOrder.

Assets Management

Asset management (specifically for sprites, LDTK maps, and tilemaps) has been reworked to reduce the amount of manual loading and coordinating of resources for these components. Loading and spawning components that require multiple assets has been greatly simplified.

New Features

There's also a smattering of new, smaller features:

  • You can now control zoom levels on your camera
  • Graphics are snapped to 0.1 pixels which seems to eliminate "pulsing" and "flashing" at certain moments.
  • Paths in LDTK levels are now recognized and usable.
  • Sprites can have repeating textures, allowing you to draw a sprite "tiled" across an area in a single draw, similar to a tilemap.

Ground-up rewrite

Beyond the changes to the "public interface" of 2B2D, just about every major system has been rewritten from the ground up. For example, rendering has been reorganized and simplified in many ways. I'm sure there are dozens of minor tweaks and changes I've long since forgotten about.

When I started 2B2D (at that time creatively named 2d-game-engine), my intention was to make a "minimally viable product" game engine, or at the very least something that could render and animate 2D textured sprites via WebGPU, without relying on other libraries. Since that first commit (one year ago, nearly to the day) it's obviously grown and evolved quite a bit. It's gone from a barely functional tech demo, to... well... pretty much still a barely functional tech demo, but now with an animated logo! I don't imagine much will come of 2B2D outside of the joy (and frustration) I've gotten from working on it, but I figure that's already more than enough.

Honestly, I expected to have abandoned this project by now. I find myself thinking, "I'm probably about done with this," only to later wonder "how hard would it be to implement change tracking, so I'm not refilling buffers unnecessarily on the GPU?"  At some point I said I wouldn't make this an NPM package, because that would "give it an air of legitimacy it simply does not warrant" (or something like that), now I find myself idly googling what a well structured NPM-destined project looks like. So, maybe I'm not quite ready to abandon this... just yet.

Files

v3.0.1.zip 2.4 MB
May 04, 2024

Leave a comment

Log in with itch.io to leave a comment.