SpriteComponent constructor

SpriteComponent({
  1. Sprite? sprite,
  2. bool? autoResize,
  3. Paint? paint,
  4. Vector2? position,
  5. Vector2? size,
  6. Vector2? scale,
  7. double? angle,
  8. double nativeAngle = 0,
  9. Anchor? anchor,
  10. Iterable<Component>? children,
  11. int? priority,
  12. ComponentKey? key,
})

Creates a component with an empty sprite which can be set later

Implementation

SpriteComponent({
  Sprite? sprite,
  bool? autoResize,
  Paint? paint,
  super.position,
  Vector2? size,
  super.scale,
  super.angle,
  super.nativeAngle,
  super.anchor,
  super.children,
  super.priority,
  super.key,
})  : assert(
        (size == null) == (autoResize ?? size == null),
        '''If size is set, autoResize should be false or size should be null when autoResize is true.''',
      ),
      _autoResize = autoResize ?? size == null,
      _sprite = sprite,
      super(size: size ?? sprite?.srcSize) {
  if (paint != null) {
    this.paint = paint;
  }

  /// Register a listener to differentiate between size modification done by
  /// external calls v/s the ones done by [_resizeToSprite].
  this.size.addListener(_handleAutoResizeState);
}