mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 12:28:03 +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:
32
lib/particles/computed_particle.dart
Normal file
32
lib/particles/computed_particle.dart
Normal file
@ -0,0 +1,32 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../particle.dart';
|
||||
|
||||
/// A function which should render desired contents
|
||||
/// onto a given canvas. External state needed for
|
||||
/// rendering should be stored elsewhere, so that this delegate could use it
|
||||
typedef ParticleRenderDelegate = void Function(Canvas c, Particle particle);
|
||||
|
||||
/// An abstract [Particle] container which delegates renderign outside
|
||||
/// Allows to implement very interesting scenarios from scratch.
|
||||
class ComputedParticle extends Particle {
|
||||
// A delegate function which will be called
|
||||
// to render particle on each frame
|
||||
ParticleRenderDelegate renderer;
|
||||
|
||||
ComputedParticle({
|
||||
@required this.renderer,
|
||||
double lifespan,
|
||||
Duration duration,
|
||||
}) : super(
|
||||
lifespan: lifespan,
|
||||
duration: duration,
|
||||
);
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
renderer(canvas, this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user