feat: Add FpsComponent and FpsTextComponent (#1595)

This commit is contained in:
Lukas Klingsbo
2022-05-11 19:49:14 +02:00
committed by GitHub
parent 02be4acd87
commit 4c68c2b0a2
14 changed files with 166 additions and 71 deletions

View File

@ -8,7 +8,7 @@ import 'package:flame/sprite.dart';
import 'package:flame/timer.dart' as flame_timer;
import 'package:flutter/material.dart' hide Image;
class ParticlesExample extends FlameGame with FPSCounter {
class ParticlesExample extends FlameGame {
static const String description = '''
In this example we show how to render a lot of different particles.
''';
@ -25,9 +25,6 @@ class ParticlesExample extends FlameGame with FPSCounter {
Timer? spawnTimer;
final StepTween steppedTween = StepTween(begin: 0, end: 5);
final trafficLight = TrafficLightComponent();
final TextPaint fpsTextPaint = TextPaint(
style: const TextStyle(color: Colors.white),
);
/// Defines the lifespan of all the particles in these examples
final sceneDuration = const Duration(seconds: 1);
@ -482,22 +479,6 @@ class ParticlesExample extends FlameGame with FPSCounter {
);
}
@override
bool debugMode = true;
@override
void render(Canvas canvas) {
super.render(canvas);
if (debugMode) {
fpsTextPaint.render(
canvas,
'${fps(120).toStringAsFixed(2)}fps',
Vector2(0, size.y - 24),
);
}
}
/// Returns random [Vector2] within a virtual grid cell
Vector2 randomCellVector2() {
return (Vector2.random() - Vector2.random())..multiply(cellSize);