Files
flame/examples/lib/stories/utils/timer_component.dart
Erick abc29dbc58 Improving TimerComponent API (#1085)
* Improving TimerComponent API

* pr suggestion

* Update packages/flame/lib/src/components/timer_component.dart

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>

* pr suggestion

* docs

* pr suggestions

* fixing

* renaming to onTick

* Update packages/flame/lib/src/components/timer_component.dart

Co-authored-by: Luan Nico <luanpotter27@gmail.com>

* Apply suggestions from code review

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>

* fixing issues

* fixing flmae bloc isse

* more suggestions

* Update packages/flame/lib/src/timer.dart

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
Co-authored-by: Luan Nico <luanpotter27@gmail.com>
2021-11-15 14:55:18 +00:00

40 lines
890 B
Dart

import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flutter/material.dart';
class RenderedTimeComponent extends TimerComponent {
final TextPaint textPaint = TextPaint(
style: const TextStyle(color: Colors.white),
);
final double yOffset;
RenderedTimeComponent(double period, {this.yOffset = 150})
: super(
period: period,
removeOnFinish: true,
);
@override
void render(Canvas canvas) {
textPaint.render(
canvas,
'Elapsed time: ${timer.current.toStringAsFixed(3)}',
Vector2(10, yOffset),
);
}
}
class TimerComponentGame extends FlameGame with TapDetector, DoubleTapDetector {
@override
void onTap() {
add(RenderedTimeComponent(1));
}
@override
void onDoubleTap() {
add(RenderedTimeComponent(5, yOffset: 180));
}
}