Skip to content

Commit

Permalink
fix: Do not scale debug data with zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Lis committed Oct 13, 2023
1 parent e2463f6 commit f69ce14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/flame/lib/src/components/core/component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,10 @@ 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;
if (!_debugTextPaintCache.isCacheValid([debugColor])) {
final textPaint = TextPaint(
style: TextStyle(color: debugColor, fontSize: 12),
style: TextStyle(color: debugColor, fontSize: 12 / zoom),
);
_debugTextPaintCache.updateCache(textPaint, [debugColor]);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/flame/lib/src/components/position_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:math' as math;
import 'dart:ui' hide Offset;

import 'package:collection/collection.dart';
import 'package:flame/camera.dart';
import 'package:flame/src/anchor.dart';
import 'package:flame/src/components/core/component.dart';
import 'package:flame/src/components/mixins/coordinate_transform.dart';
Expand Down Expand Up @@ -429,6 +430,7 @@ class PositionComponent extends Component

@override
void renderDebugMode(Canvas canvas) {
final zoom = CameraComponent.currentCamera?.viewfinder.zoom ?? 1.0;
super.renderDebugMode(canvas);
final precision = debugCoordinatesPrecision;
canvas.drawRect(size.toRect(), debugPaint);
Expand All @@ -444,7 +446,7 @@ class PositionComponent extends Component
debugTextPaint.render(
canvas,
'x:$x1str y:$y1str',
Vector2(-10 * (precision + 3), -15),
Vector2(-10 * (precision + 3) / zoom, -15 / zoom),
);
// print coordinates at the bottom-right corner
final p2 = absolutePositionOfAnchor(Anchor.bottomRight);
Expand All @@ -453,7 +455,7 @@ class PositionComponent extends Component
debugTextPaint.render(
canvas,
'x:$x2str y:$y2str',
Vector2(size.x - 10 * (precision + 3), size.y),
Vector2(size.x - 10 * (precision + 3) / zoom, size.y),
);
}
}
Expand Down

0 comments on commit f69ce14

Please sign in to comment.