flutter/examples/game/lib/flash.dart

24 lines
722 B
Dart

part of game;
class Flash extends NodeWithSize {
Flash(Size size, this.duration) : super(size) {
ActionTween fade = new ActionTween((a) => _opacity = a, 1.0, 0.0, duration);
ActionSequence seq = new ActionSequence([fade, new ActionRemoveNode(this)]);
actions.run(seq);
}
double duration;
double _opacity = 1.0;
Paint _cachedPaint = new Paint();
void paint(PaintingCanvas canvas) {
// Update the color
_cachedPaint.color = new Color.fromARGB((255.0 * _opacity).toInt(),
255, 255, 255);
// Fill the area
applyTransformForPivot(canvas);
canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height),
_cachedPaint);
}
}