Files
flame/examples/lib/stories/input/joystick_example.dart
2022-01-24 23:23:12 +01:00

33 lines
1.0 KiB
Dart

import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/palette.dart';
import 'package:flutter/painting.dart';
import 'joystick_player.dart';
class JoystickExample extends FlameGame with HasDraggables {
static const String description = '''
In this example we showcase how to use the joystick by creating simple
`CircleComponent`s that serve as the joystick's knob and background.
Steer the player by using the joystick.
''';
late final JoystickPlayer player;
late final JoystickComponent joystick;
@override
Future<void> onLoad() async {
final knobPaint = BasicPalette.blue.withAlpha(200).paint();
final backgroundPaint = BasicPalette.blue.withAlpha(100).paint();
joystick = JoystickComponent(
knob: CircleComponent(radius: 30, paint: knobPaint),
background: CircleComponent(radius: 100, paint: backgroundPaint),
margin: const EdgeInsets.only(left: 40, bottom: 40),
);
player = JoystickPlayer(joystick);
add(player);
add(joystick);
}
}