mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 12:28:03 +08:00
fix: doc/example/particles/readme, attempt to embed webm preview fix: doc/example/particles better sample for chaining refactor: Particle, dropped duration support
37 lines
909 B
Dart
37 lines
909 B
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import '../particle.dart';
|
|
|
|
/// A [Particle] which renders given [Image] on a [Canvas]
|
|
/// image is centered. If any other behavior is needed, consider
|
|
/// using [ComputedParticle].
|
|
class ImageParticle extends Particle {
|
|
/// dart.ui [Image] to draw
|
|
Image image;
|
|
|
|
Rect src;
|
|
Rect dest;
|
|
|
|
ImageParticle({
|
|
@required this.image,
|
|
Size size,
|
|
double lifespan,
|
|
}) : super(lifespan: lifespan) {
|
|
final srcWidth = image.width.toDouble();
|
|
final srcHeight = image.height.toDouble();
|
|
final destWidth = size?.width ?? srcWidth;
|
|
final destHeight = size?.height ?? srcHeight;
|
|
|
|
src = Rect.fromLTWH(0, 0, srcWidth, srcHeight);
|
|
dest =
|
|
Rect.fromLTWH(-destWidth / 2, -destHeight / 2, destWidth, destHeight);
|
|
}
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
canvas.drawImageRect(image, src, dest, Paint());
|
|
}
|
|
}
|