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:
Ivan Cherepanov
2019-11-28 18:01:31 +03:00
parent ce0b99ecbd
commit ff425afa26
26 changed files with 1828 additions and 165 deletions

View 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());
}
}