forge2d
0.15.3, released 5 weeks ago by flame-engine.org
A 2D physics engine for Dart, binding to the native Box2D v3 library.
WASM-ready
What it does
Provides an idiomatic Dart API for the native Box2D v3 physics engine. Supports simulations running at native speed via FFI across multiple platforms, and also works with the Flame game engine.
AI-written summary of version 0.15.3, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are building a 2D game in Dart or Flutter requiring rigid body physics.
- You are using the Flame game engine and need advanced 2D collision detection and gravity.
Skip it when
- You are building standard business apps or UIs that do not require physics simulations.
- You cannot include a native C toolchain for compilation on target desktop/mobile platforms.
Strengths
- High performance via native Box2D v3 bindings and WebAssembly on the web.
- Integrates seamlessly with the Flame game engine.
Weaknesses
- Requires a C toolchain on native platforms (Xcode, Visual Studio, gcc/clang, NDK).
- Breaking changes from older versions require manual migration.
Setup
- Kind
- FFI (native library)
- Effort
- Medium
- Code generation
- No
- Direct dependencies
- 7
Requires a C toolchain on native platforms (Xcode, Visual Studio, clang/gcc, NDK) and calling await initializeForge2D() at startup.
import 'package:forge2d/forge2d.dart';
Future<void> main() async {
await initializeForge2D();
final world = World();
world.createBody(BodyDef(position: Vector2(0, -1))).createShape(Polygon.box(50, 1));
world.destroy();
}Alternatives
Packages that do the same job and could replace forge2d.
Works with
Packages commonly used together with forge2d: ones it builds on, ones built on it, and its own family.
- hooksforge2d depends on itDart API for the JSON-based protocol for package build and link hooks.
- code_assetsforge2d depends on itProvides the hook protocol specification for bundling native code with Dart packages.
- ffiforge2d depends on itUtilities for working with Foreign Function Interface (FFI) code in Dart.
- loggingforge2d depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- vector_mathforge2d depends on itVector math library for 2D/3D/4D vectors, matrices, quaternions, and geometry.
- native_toolchain_cforge2d depends on itInvoke the native C compiler installed on the host machine.
- flame_forge2dBuilt on forge2dForge2D physics engine support and wrappers for the Flame game engine.
- pretty_animated_textBuilt on forge2dA Flutter plugin for creating customizable animated text widgets, enhancing app aesthetics with engaging text animations.