mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 08:56:01 +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 { | ||||
|     await super.onLoad(); | ||||
|     svgInstance = await loadSvg('android.svg'); | ||||
|     final android = SvgComponent.fromSvg( | ||||
|       svgInstance, | ||||
|     final android = SvgComponent( | ||||
|       svg: svgInstance, | ||||
|       position: Vector2.all(100), | ||||
|       size: Vector2.all(100), | ||||
|     ); | ||||
|  | ||||
| @ -11,8 +11,7 @@ environment: | ||||
| dependencies: | ||||
|   flutter: | ||||
|     sdk: flutter | ||||
|   flame: | ||||
|     path: ../../flame | ||||
|   flame: ^1.0.0 | ||||
|   flame_svg: | ||||
|     path: ../ | ||||
|  | ||||
|  | ||||
| @ -7,18 +7,51 @@ import './svg.dart'; | ||||
| /// Wraps [Svg] in a Flame component. | ||||
| class SvgComponent extends PositionComponent { | ||||
|   /// The wrapped instance of [Svg]. | ||||
|   Svg svg; | ||||
|   Svg? svg; | ||||
|  | ||||
|   /// Creates an [SvgComponent] from an [Svg] instance. | ||||
|   SvgComponent.fromSvg( | ||||
|     this.svg, { | ||||
|   /// Creates an [SvgComponent] | ||||
|   SvgComponent({ | ||||
|     this.svg, | ||||
|     Vector2? position, | ||||
|     Vector2? size, | ||||
|     Vector2? scale, | ||||
|     double? angle, | ||||
|     Anchor? anchor, | ||||
|     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 | ||||
|   void render(Canvas canvas) { | ||||
|     svg.render(canvas, size); | ||||
|     svg?.render(canvas, size); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -9,8 +9,7 @@ environment: | ||||
|   flutter: ">=2.5.0" | ||||
|  | ||||
| dependencies: | ||||
|   flame: | ||||
|     path: ../flame | ||||
|   flame: ^1.0.0 | ||||
|   flutter_svg: ^0.22.0 | ||||
|   flutter: | ||||
|     sdk: flutter | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Erick
					Erick