mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 21:17:13 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			59 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() {
 | 
						|
  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);
 | 
						|
  }
 | 
						|
}
 |