Skip to content

Commit

Permalink
fix: Set margins of JoystickComponent properly
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon committed Feb 5, 2024
1 parent bf8aecd commit fab0efa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions examples/lib/stories/input/joystick_advanced_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class JoystickAdvancedExample extends FlameGame with HasCollisionDetection {
the buttons.
''';

JoystickAdvancedExample()
: super(
camera: CameraComponent.withFixedResolution(width: 1200, height: 800),
);

late final JoystickPlayer player;
late final JoystickComponent joystick;
late final TextComponent speedText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:math';
import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flame/src/components/input/hud_margin_component.dart';

Check warning on line 5 in packages/flame/lib/src/components/input/joystick_component.dart

View workflow job for this annotation

GitHub Actions / analyze

Unused import: 'package:flame/src/components/input/hud_margin_component.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unused_import to learn more about this problem.

Check warning on line 5 in packages/flame/lib/src/components/input/joystick_component.dart

View workflow job for this annotation

GitHub Actions / analyze-latest

Unused import: 'package:flame/src/components/input/hud_margin_component.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unused_import to learn more about this problem.
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';

Check notice on line 7 in packages/flame/lib/src/components/input/joystick_component.dart

View workflow job for this annotation

GitHub Actions / analyze

The import of 'package:meta/meta.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/widgets.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unnecessary_import to learn more about this problem.

Check notice on line 7 in packages/flame/lib/src/components/input/joystick_component.dart

View workflow job for this annotation

GitHub Actions / analyze-latest

The import of 'package:meta/meta.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/widgets.dart'.

Try removing the import directive. See https://dart.dev/diagnostics/unnecessary_import to learn more about this problem.

enum JoystickDirection {
Expand All @@ -17,7 +18,8 @@ enum JoystickDirection {
idle,
}

class JoystickComponent extends HudMarginComponent with DragCallbacks {
class JoystickComponent extends PositionComponent
with HasGameReference, ComponentViewportMargin, DragCallbacks {
late final PositionComponent? knob;
late final PositionComponent? background;

Expand Down Expand Up @@ -46,8 +48,8 @@ class JoystickComponent extends HudMarginComponent with DragCallbacks {
JoystickComponent({
this.knob,
this.background,
super.margin,
super.position,
EdgeInsets? margin,
double? size,
double? knobRadius,
Anchor super.anchor = Anchor.center,
Expand All @@ -66,6 +68,7 @@ class JoystickComponent extends HudMarginComponent with DragCallbacks {
super(
size: background?.size ?? Vector2.all(size ?? 0),
) {
this.margin = margin;
this.knobRadius = knobRadius ?? this.size.x / 2;
}

Expand Down

0 comments on commit fab0efa

Please sign in to comment.