I am working on a Flutter project, utilizing the Flame game engine and the Forge2D library for physics simulation. I need to add collisions for my SVG elements in the game. I already know how to render SVG in Flame, but I am unsure about how to create collision shapes for SVG in Forge2D. Is there a way to create collision shapes based on SVG? Any examples or recommendations would be very helpful.
Thank you!
I tried to find SvgShape but I didn't find it
@override
Body createBody() {
final shape = CircleShape();
shape.radius = size.x;
final fixtureDef = FixtureDef(
shape,
userData: this,
restitution: 1,
density: 15,
friction: 1,
);
final bodyDef = BodyDef(
position: initialPosition,
angle: 0,
type: BodyType.dynamic,
gravityScale: Vector2.all(3.5),
);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
There is unfortunately nothing built-in to do this, and Forge2D also only support convex shapes.
A lot of SVGs wouldn't be supported either since only rectangles, polygons and circle shapes are supported, so it couldn't support arc curves and paths for example.