Files
Lukas Klingsbo 3cb23ef530 TextPaint to use TextStyle instead of TextPaintConfig (#1086)
* `TextPaint` to use `TextStyle` instead of `TextPaintConfig`

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

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

* Removed BaseTextConfig and TextPaintConfig

* Update text docs

* Apply suggestions from code review

Co-authored-by: Erick <erickzanardoo@gmail.com>

* Remove generics

* Update TextBoxExample

* Update text examples variable names

* Fix TextPaint in collision_detection example

Co-authored-by: Pasha Stetsenko <stpasha@google.com>
Co-authored-by: Erick <erickzanardoo@gmail.com>
2021-11-13 16:38:06 +01:00

58 lines
1.4 KiB
Dart

import 'package:flame/game.dart';
import 'package:flame_oxygen/flame_oxygen.dart';
import 'package:flutter/material.dart';
class DebugSystem extends BaseSystem {
final debugPaint = Paint()
..color = Colors.green
..style = PaintingStyle.stroke;
final textPainter = TextPaint(
style: const TextStyle(color: Colors.green, fontSize: 10),
);
final statusPainter = TextPaint(
style: const TextStyle(color: Colors.green, fontSize: 16),
);
@override
List<Filter<Component>> get filters => [];
@override
void render(Canvas canvas) {
super.render(canvas);
statusPainter.render(
canvas,
[
'FPS: ${(world!.game as FPSCounter).fps()}',
'Entities: ${world!.entities.length}',
].join('\n'),
Vector2.zero(),
);
}
@override
void renderEntity(Canvas canvas, Entity entity) {
final size = entity.get<SizeComponent>()!.size;
canvas.drawRect(Vector2.zero() & size, debugPaint);
textPainter.render(
canvas,
[
'position: ${entity.get<PositionComponent>()!.position}',
'size: $size',
'angle: ${entity.get<AngleComponent>()?.radians ?? 0}',
'anchor: ${entity.get<AnchorComponent>()?.anchor ?? Anchor.topLeft}',
].join('\n'),
Vector2(size.x + 2, 0),
);
textPainter.render(
canvas,
entity.name ?? '',
Vector2(size.x / 2, size.y + 2),
anchor: Anchor.topCenter,
);
}
}