flash.dart 722 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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);
  }
}