mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-16 04:38:42 +08:00
Move files to src and comply with the dart package layout convention (#621)
* 👌 Use `Offset` type directly in `JoystickAction.update` calculations (#631) * Move files to src and comply with the dart package layout convention * Fixing widgets example Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
This commit is contained in:
46
lib/src/components/sprite_component.dart
Normal file
46
lib/src/components/sprite_component.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../extensions/vector2.dart';
|
||||
import '../sprite.dart';
|
||||
import 'component.dart';
|
||||
import 'position_component.dart';
|
||||
|
||||
export '../sprite.dart';
|
||||
|
||||
/// A [PositionComponent] that renders a single [Sprite] at the designated
|
||||
/// position, scaled to have the designated size and rotated to the specified
|
||||
/// angle.
|
||||
///
|
||||
/// This a commonly used subclass of [Component].
|
||||
class SpriteComponent extends PositionComponent {
|
||||
/// The [sprite] to be rendered by this component.
|
||||
Sprite sprite;
|
||||
|
||||
/// Use this to override the colour used (to apply tint or opacity).
|
||||
///
|
||||
/// If not provided the default is full white (no tint).
|
||||
Paint overridePaint;
|
||||
|
||||
/// Creates a component with an empty sprite which can be set later
|
||||
SpriteComponent();
|
||||
|
||||
SpriteComponent.fromImage(Vector2 size, Image image)
|
||||
: this.fromSprite(size, Sprite(image));
|
||||
|
||||
SpriteComponent.fromSprite(Vector2 size, this.sprite) {
|
||||
super.size.setFrom(size);
|
||||
}
|
||||
|
||||
@mustCallSuper
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
sprite?.render(
|
||||
canvas,
|
||||
size: size,
|
||||
overridePaint: overridePaint,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user