Files
flame/examples/lib/stories/input/joystick_example.dart
Lukas Klingsbo 152fbb61db docs: Fix examples for v1.9.0 (#2757)
Fixed up some examples that needed fixing before releasing v1.9.0
2023-09-21 19:24:40 +00:00

32 lines
1.1 KiB
Dart

import 'package:examples/stories/input/joystick_player.dart';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/palette.dart';
import 'package:flutter/painting.dart';
class JoystickExample extends FlameGame {
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);
world.add(player);
camera.viewport.add(joystick);
}
}