mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
56 lines
1.3 KiB
Dart
56 lines
1.3 KiB
Dart
import 'package:flame/components/joystick/joystick_action.dart';
|
|
import 'package:flame/components/joystick/joystick_component.dart';
|
|
import 'package:flame/components/joystick/joystick_directional.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'player.dart';
|
|
|
|
void main() {
|
|
final game = MyGame();
|
|
runApp(game.widget);
|
|
}
|
|
|
|
class MyGame extends BaseGame with MultiTouchDragDetector {
|
|
final player = Player();
|
|
final joystick = JoystickComponent(
|
|
directional: JoystickDirectional(),
|
|
actions: [
|
|
JoystickAction(
|
|
actionId: 1,
|
|
size: 50,
|
|
margin: const EdgeInsets.all(50),
|
|
color: const Color(0xFF0000FF),
|
|
),
|
|
JoystickAction(
|
|
actionId: 2,
|
|
size: 50,
|
|
color: const Color(0xFF00FF00),
|
|
margin: const EdgeInsets.only(
|
|
right: 50,
|
|
bottom: 120,
|
|
),
|
|
),
|
|
JoystickAction(
|
|
actionId: 3,
|
|
size: 50,
|
|
margin: const EdgeInsets.only(bottom: 50, right: 120),
|
|
enableDirection: true,
|
|
),
|
|
],
|
|
);
|
|
|
|
MyGame() {
|
|
joystick.addObserver(player);
|
|
add(player);
|
|
add(joystick);
|
|
}
|
|
|
|
@override
|
|
void onReceiveDrag(DragEvent drag) {
|
|
joystick.onReceiveDrag(drag);
|
|
super.onReceiveDrag(drag);
|
|
}
|
|
}
|