mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 20:36:31 +08:00
feat: docs, adde particles docs
fix: doc/examples/particles, added web to .gitignore feat: doc/examples/particles, added more examples, refactor: Particle does not extend Component refactor: Particle subclasses in separate folder refactor: ParticleComponent is now simple container fix: SingleChildParticle, asserts for child existing feat: AnimationParticle for Flame Animation feat: ComponentParticle for Flame Component feat: SpriteParticle for Flame Sprite
This commit is contained in:
37
lib/particles/image_particle.dart
Normal file
37
lib/particles/image_particle.dart
Normal file
@ -0,0 +1,37 @@
|
||||
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,
|
||||
Duration duration,
|
||||
}) : super(lifespan: lifespan, duration: duration) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user