Flame SVG¶
flame_svg provides a simple API for rendering SVG images in your game.
Installation¶
Svg support is provided by the flame_svg
bridge package, be sure to put it in your pubspec file
to use it.
If you want to know more about the installation visit flame_svg on pub.dev.
How to use flame_svg¶
To use it just import the Svg
class from 'package:flame_svg/flame_svg.dart'
, and use the
following snippet to render it on the canvas:
final svgInstance = await Svg.load('android.svg');
final position = Vector2(100, 100);
final size = Vector2(300, 300);
svgInstance.renderPosition(canvas, position, size);
or use the SvgComponent
and add it to the component tree:
class MyGame extends FlameGame {
@override
Future<void> onLoad() async {
final svgInstance = await Svg.load('android.svg');
final size = Vector2.all(100);
final position = Vector2.all(100);
final svgComponent = SvgComponent(
size: size,
position: position,
svg: svgInstance,
);
add(svgComponent);
}
}
The content on this page is licensed under the CC BY 4.0 License,
and code samples under the MIT License.