Skip to content

Commit

Permalink
feat: Using viewport scale on debug mode text paint (#2883)
Browse files Browse the repository at this point in the history
Consider viewport scaling into the text paint used in the debug
information of components.

Fixes #2881
  • Loading branch information
erickzanardo committed Nov 29, 2023
1 parent 0fd2662 commit 07ef46c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/flame/lib/src/components/core/component.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:math' as math;

import 'package:collection/collection.dart';
import 'package:flame/components.dart';
Expand Down Expand Up @@ -974,10 +975,21 @@ class Component {
/// Returns a [TextPaint] object with the [debugColor] set as color for the
/// text.
TextPaint get debugTextPaint {
final zoom = CameraComponent.currentCamera?.viewfinder.zoom ?? 1.0;
final viewfinder = CameraComponent.currentCamera?.viewfinder;
final viewport = CameraComponent.currentCamera?.viewport;
final zoom = viewfinder?.zoom ?? 1.0;

final viewportScale = math.max(
viewport?.transform.scale.x ?? 1,
viewport?.transform.scale.y ?? 1,
);

if (!_debugTextPaintCache.isCacheValid([debugColor])) {
final textPaint = TextPaint(
style: TextStyle(color: debugColor, fontSize: 12 / zoom),
style: TextStyle(
color: debugColor,
fontSize: 12 / zoom / viewportScale,
),
);
_debugTextPaintCache.updateCache(textPaint, [debugColor]);
}
Expand Down

0 comments on commit 07ef46c

Please sign in to comment.