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

@ -1,17 +1,13 @@
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
class DebugExample extends FlameGame with FPSCounter {
class DebugExample extends FlameGame {
static const String description = '''
In this example we show what you will see when setting `debugMode = true` on
your game. It is a non-interactive example.
In this example we show what you will see when setting `debugMode = true`
and add the `FPSTextComponent` to your game.
This is a non-interactive example.
''';
static final fpsTextPaint = TextPaint(
style: const TextStyle(color: Color(0xFFFFFFFF)),
);
@override
bool debugMode = true;
@ -36,15 +32,8 @@ class DebugExample extends FlameGame with FPSCounter {
add(flame1);
add(flame2);
add(flame3);
}
@override
void render(Canvas canvas) {
super.render(canvas);
if (debugMode) {
fpsTextPaint.render(canvas, fps(120).toString(), Vector2(0, 50));
}
add(FpsTextComponent(position: Vector2(0, size.y - 24)));
}
}