mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-31 00:48:47 +08:00
feat: adding default constructor on SvgComponent (#1334)
* feat: adding default constructor on SvgComponent * fixing flame version * svg not final anymore * pr suggestions
This commit is contained in:
@ -19,8 +19,8 @@ class MyGame extends FlameGame {
|
|||||||
Future<void> onLoad() async {
|
Future<void> onLoad() async {
|
||||||
await super.onLoad();
|
await super.onLoad();
|
||||||
svgInstance = await loadSvg('android.svg');
|
svgInstance = await loadSvg('android.svg');
|
||||||
final android = SvgComponent.fromSvg(
|
final android = SvgComponent(
|
||||||
svgInstance,
|
svg: svgInstance,
|
||||||
position: Vector2.all(100),
|
position: Vector2.all(100),
|
||||||
size: Vector2.all(100),
|
size: Vector2.all(100),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -11,8 +11,7 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flame:
|
flame: ^1.0.0
|
||||||
path: ../../flame
|
|
||||||
flame_svg:
|
flame_svg:
|
||||||
path: ../
|
path: ../
|
||||||
|
|
||||||
|
|||||||
@ -7,18 +7,51 @@ import './svg.dart';
|
|||||||
/// Wraps [Svg] in a Flame component.
|
/// Wraps [Svg] in a Flame component.
|
||||||
class SvgComponent extends PositionComponent {
|
class SvgComponent extends PositionComponent {
|
||||||
/// The wrapped instance of [Svg].
|
/// The wrapped instance of [Svg].
|
||||||
Svg svg;
|
Svg? svg;
|
||||||
|
|
||||||
/// Creates an [SvgComponent] from an [Svg] instance.
|
/// Creates an [SvgComponent]
|
||||||
SvgComponent.fromSvg(
|
SvgComponent({
|
||||||
this.svg, {
|
this.svg,
|
||||||
Vector2? position,
|
Vector2? position,
|
||||||
Vector2? size,
|
Vector2? size,
|
||||||
|
Vector2? scale,
|
||||||
|
double? angle,
|
||||||
|
Anchor? anchor,
|
||||||
int? priority,
|
int? priority,
|
||||||
}) : super(position: position, size: size, priority: priority);
|
}) : super(
|
||||||
|
position: position,
|
||||||
|
size: size,
|
||||||
|
scale: scale,
|
||||||
|
angle: angle,
|
||||||
|
anchor: anchor,
|
||||||
|
priority: priority,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Creates an [SvgComponent] from an [Svg] instance.
|
||||||
|
@Deprecated(
|
||||||
|
'Will be removed on future versions, use the default '
|
||||||
|
'constructor instead',
|
||||||
|
)
|
||||||
|
SvgComponent.fromSvg(
|
||||||
|
Svg svg, {
|
||||||
|
Vector2? position,
|
||||||
|
Vector2? size,
|
||||||
|
Vector2? scale,
|
||||||
|
double? angle,
|
||||||
|
Anchor? anchor,
|
||||||
|
int? priority,
|
||||||
|
}) : this(
|
||||||
|
svg: svg,
|
||||||
|
position: position,
|
||||||
|
size: size,
|
||||||
|
scale: scale,
|
||||||
|
angle: angle,
|
||||||
|
anchor: anchor,
|
||||||
|
priority: priority,
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void render(Canvas canvas) {
|
void render(Canvas canvas) {
|
||||||
svg.render(canvas, size);
|
svg?.render(canvas, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,7 @@ environment:
|
|||||||
flutter: ">=2.5.0"
|
flutter: ">=2.5.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flame:
|
flame: ^1.0.0
|
||||||
path: ../flame
|
|
||||||
flutter_svg: ^0.22.0
|
flutter_svg: ^0.22.0
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|||||||
Reference in New Issue
Block a user