mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
* 👌 Use `Offset` type directly in `JoystickAction.update` calculations (#631) * Move files to src and comply with the dart package layout convention * Fixing widgets example Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
57 lines
1.1 KiB
Dart
57 lines
1.1 KiB
Dart
import 'package:flame/game.dart';
|
|
import 'package:flame/gestures.dart';
|
|
import 'package:flame/joystick.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'player.dart';
|
|
|
|
void main() {
|
|
runApp(
|
|
GameWidget(
|
|
game: MyGame(),
|
|
),
|
|
);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|